Download presentation
Presentation is loading. Please wait.
Published byDenis Hensley Modified over 9 years ago
1
Process to process communication over network connections Includes references to Comer and Stevens Internetworking with TCP/IP vol 3 Client-server programming and applications
2
Program to protocol 4 Network protocols allow message exchange between systems connected by networks 4 Application programs must connect to the network protocol implementations in the local systems to carry their messages 4 Two sides needed: send and receive 4 Program activity coordination is a separate issue
3
Client - Server Computing 4 Direction of initiation determines which side is which –Client initiates –Server responds 4 Same system may be client and server
4
Parameterization of clients 4 Parameter specifies machine where server resides 4 Optional parameter specifies the port where the server listens –Include the port number parameter in defining clients –Especially useful for testing new versions 4 ex: telnet doyle.netlab.csc.villanova.edu 23
5
Addressing 4 Specify the machine –name gets converted to IP address 4 Specify the port number –Which running process to connect to.
6
How do you know 4 Which machine –you have to know the name or the IP address of the partner Names get converted by a Domain Name Service 4 Which port –Common services have assigned port numbers –telnet = 23, http = 80, etc.
7
Port numbers 4 The port numbers are divided into three ranges: the Well Known Ports, the Registered Ports, and the Dynamic and/or Private Ports. 4 Well Known Ports: 0 through 1023. 4 Registered Ports: 1024 through 49151 4 Dynamic and/or Private Ports: 49152 through 65535 Ref: http://www.isi.edu/in-notes/iana/assignments/port-numbers
8
Well known Port number samples ssh 22 telnet 23 smtp 25 sql*net 66 bootps 67 (bootstrap server) bootpc 68 (bootstrap client) http 80 kerberos 88 npp 92 (network print) iso tsap 102 (class 0 ) pop3 110 Sun rpc 111 nntp 119 (network news) daytime 13/tcp Daytime (RFC 867) daytime 13/udp Daytime (RFC 867) ftp-data 20/tcp File Transfer [Default Data] ftp-data 20/udp File Transfer [Default Data] ftp 21/tcp File Transfer [Control] ftp 21/udp File Transfer [Control]
9
Domain Name Service 4 Structure of Internet Names –gadget.netlab.csc.villanova.edu –Lookup in order from right to left netlab and csc are both entries in the villanova DNS, so that lookup can go directly from villanova to netlab without using the csc DNS That is always an option in configuring the servers
10
DNS - Christie’s table ; Addresses for the canonical names ; localhost.netlab.csc.villanova.edu. IN A 127.0.0.1 christie.netlab.csc.villanova.edu. IN A 153.104.203.200 doyle.netlab.csc.villanova.edu. IN A 153.104.203.210 gadget.netlab.csc.villanova.edu. IN A 153.104.203.42 missmarple.netlab.csc.villanova.edu. IN A 153.104.203.7 lordpeter.netlab.csc.villanova.edu. IN A 153.104.203.41 poirot.netlab.csc.villanova.edu. IN A 153.104.203.148 koko.netlab.csc.villanova.edu. IN A 153.104.203.45 sherlock.netlab.csc.villanova.edu. IN A 153.104.203.44 cadfael.netlab.csc.villanova.edu. IN A 153.104.203.43 columbo.netlab.csc.villanova.edu. IN A 153.104.203.46 weber.netlab.csc.villanova.edu. IN A 153.104.203.205 matlock.netlab.csc.villanova.edu. IN A 153.104.203.203 samspade.netlab.csc.villanova.edu. IN A 153.104.203.204 poe.netlab.csc.villanova.edu. IN A 153.104.203.50
11
Which domain server to use A configuration option Example for Windows
12
Port number usage 4 When writing a new application, allow the user to specify the port number or to use the default 4 Some implementations do not allow the user to specify a port number –uses the protocol’s reserved number only –Allowing a port number to be specified makes it easier to test the implementation allow the “real” version to run while testing a different version
13
Server 4 Usually runs in privileged condition –needs to access protected resources –be careful about what access it gives to clients 4 Responsibilities –Authenticate client identity –Enforce authorization restrictions –Data protection: security and privacy –Protection: system resources from abuse
14
Server characteristics 4 Iterative –serve one client at a time 4 Concurrent –serve multiple clients at one time
15
Connectionless vs Connection-oriented 4 Directly related to the choice of transport protocol –UDP: connectionless –TCP: connection-oriented 4 Can build connection-oriented client/server application over a connectionless transport layer
16
Server state 4 Stateless server –no memory of past interaction –each request must be fully qualified 4 Stateful server –records state information –reduces needed content in subsequent messages –depends on reliable network communication –vulnerable to system failures, reboots
17
Idempotent operations 4 An operation that always yields the same result, regardless of repetition or missing prior steps –READ or WRITE, without automatic increment of pointer –not idempotent - increment, add amount to total, etc.
18
Concurrent processes 4 Multiprogramming –Apparent simultaneous execution 4 Multiprocessing –Real simultaneous execution
19
Server Concurrency 4 Need to serve requests from multiple clients 4 Process –Fundamental unit of computation –Address space plus at least one thread of execution instruction pointer tells where in the process the thread is currently executing
20
Threads 4 Similar to a process except –a thread is owned by a process –a thread may share common resources belonging to a process 4 A thread has a private copy of local variables
21
Concurrent processes 4 In a uniprocessor system –Each process gets a slice of the CPU time in turn –All appear to run at the same time 4 If each process has only one thread of execution, that process shares the CPU with other processes on a time sharing plan 4 If a process has more than one thread, the CPU time is divided among the threads. –OS vary: divide time among all threads or divide among processes and multiple threads share the time allotted to their parent process 4 In a multiprocessor system, each process or thread may be allocated a separate CPU
22
Threads in servers 4 A process may respond to client requests by spawning a separate thread for each client 4 Clients appear to be served simultaneously but actually receive intermingled slices of the CPU time.
23
Initiating concurrent subprocesses 4 Windows: –_beginthread parameter specifies what to execute as thread 4 unix –fork new process is a copy of the initiating process pid identifies each
24
Unix concurrency 4 fork() creates an exact copy of the calling process and continues execution from exactly the same place in the code. –Copy includes the stack showing function calls, local and global variables –Original and forked process continue from the same point in execution –One distinction: fork returns a value: new process returns 0, original returns non zero value
25
Unix concurrency example sum = 0; pid = fork(); if (pid != 0 ) { /* original */ printf (“The original process\n”); }else { /* the new process */ printf (“The new process\n”); Note that the order in which the two lines are printed may vary from one run to another.
26
Concurrency in Windows 4 _beginthread –parameter specifies what is to be executed 4 Not necessarily executing the same code as the calling process
27
Application Program Interface (API) 4 Identify endpoints of the connection 4 Establish the communication 4 Allow message send 4 Allow wait for incoming message 4 Possibly allow for incoming or outgoing high priority data 4 Graceful termination of the communication 4 Handle error situations
28
API implementation options 4 Everything embedded in the operating system 4 TCP/IP and API run in user space 4 TCP/IP in operating system; API in user space 4 Generally invisible differences for user
29
Sockets 4 A de facto standard interface to TCP/IP protocols 4 Defined in BSD unix 4 Adapted by other operating systems
30
The Socket API - connection oriented Socket() Listen() Bind() Accept() recv() send() Server Side Client Side recv() send() Connect() Socket() closesocket
31
Socket 4 Create a new socket –allocate storage for an instance of a data structure –start to fill in the values with the parameters protocol family the application will use type of service to be used 4 Newly created socket is neither active nor passive until the application does something else
32
Socket 4 Serves same purpose as Open for files 4 Same table may hold both file descriptors (created by open) and socket descriptors (created by socket) 4 Most fields in the data structure are initially empty, filled in later
33
Socket data structure 4 Family: PF_INET –(Protocol Family_Internet protocols) 4 service: SOCK_STREAM –(Using TCP, connection-oriented communication) 4 IP addresses –local and remote 4 Port numbers –local and remote
34
Addressing 4 AF_INET –Address Family Internet 4 Endpoint address
35
Socket data structure Family: PF_INET Service: SOCK_STREAM Local IP: Remote IP: Local Port: Remote port: Etc. One table per process
36
connect 4 Establish an active connection to a remote server –identify the remote end point IP address protocol port number –fill in the remote address part of the socket data structure –Choose and fill in the local address part of the socket data structure –makes the socket active –causes TCP to begin the three-way handshake
37
Three-way handshake SYN(seq=x) SYN(seq=y,ack=x+1) SYN(seq=x+1,ack=y+1) Client Server time Tell the peer what sequence number you expect to see next
38
send 4 A write operation 4 Used by clients and servers to move data 4 Non-blocking –possible brief blocking if buffers are full
39
recv 4 A read operation 4 Get incoming data from the socket 4 Note that TCP is stream-oriented –it does not recognize boundaries in the message –programs may need to loop to receive all of the incoming message –separate message segments may be combined in a single buffer retrieval 4 UDP is message-oriented –boundaries remain as the sender intended
40
closesocket 4 Deallocate the socket 4 complement of the socket call 4 if socket shared by >1 process, reference count is decremented. Socket is deallocated when the reference count reaches zero
41
bind 4 Server side 4 Fills in the local address –IP address –Port number on which the service will be available
42
listen 4 Place the socket in passive mode –ready to receive an incoming connection 4 Specify the size of a queue for incoming connection requests –How many concurrent users are we able to serve?
43
accept 4 Get the next incoming connection request 4 Peer of connect –sets up the connection between the client and server so that exchange of messages can take place 4 Create a new socket for an incoming connection request –The original socket remains available for receiving additional requests –All communication for the incoming connection goes over the new socket –When the communication is completed, the new socket is closed
44
Functions included in socket interface 4 inet_addr –takes ASCII string, dotted decimal IP address –returns binary IP address 4 gethostbyname –takes ASCII string, domain name –returns hostent structure
45
hostent structure struct hostent { char FAR*h_name; /* official host name */ char FAR* FAR*h_aliases; /* other aliases */ shorth_addrtype; /* address type */ shorth_length; /* address length */ char FAR* FAR*h_addr_list; /* list of addresses */ } #defineh_addr h_addr_list[0] Predefined and available in winsock.h (windows) struct hostent { char *h_name; /* official host name */ char **h_aliases; /* other aliases */ shorth_addrtype; /* address type */ shorth_length; /* address length */ char *h_addr_list; /* list of addresses */ } #defineh_addr h_addr_list[0] Predefined and available in netdb.h (unix)
46
Using gethostbyname Structhostent *hptr; char*examplenam = “merlin.cs.purdue.edu”; if (hptr = gethostbyname( examplenam )) { /* IP address is now in hptr->h_addr */ } else { /*error in name - handle it */ } Comer TCP/IP vol III page 65
47
Other services 4 Getservbyname –takes two strings desired service protocol –returns pointer to structure of type servent
48
Client side operation 4 Steps for a client –Find IP address and protocol port number of the server –Allocate a socket –Allow TCP to choose an arbitrary, unused local port number –Connect the socket to the server –Use the connection for application operation –Close the connection
49
Servers 4 Iterative –processes one request at a time 4 Concurrent –processes multiple requests at one time 4 Connection oriented –Uses tcp to handle packet loss and out-of-order delivery –Require a separate socket for each connection possibly resource depletion if the connection is not closed 4 Connectionless –Uses udp which provides no quality control –Multiple clients can share a single socket
50
Iterative connection-oriented server 4 Create a socket and bind to the well-known address for the service offered 4 Place a socket in passive mode 4 Accept the next connection request and obtain a new socket for the connection 4 Repeatedly receive a request from the client, formulate a response, and send a reply back to the client 4 When the client is finished, close the connection and return to the accept step for a new connection Single thread, handle connections from clients one at a time OK if each request is very short.
51
Iterative connectionless server 4 Create a socket and bind to the well-known address for the service offered 4 Repeatedly receive the next request from a client, formulate a response, and send a reply back to the client. One socket used repeatedly for new clients One client is served before another can receive attention
52
Concurrent Connectionless Server 4 Master: Create a socket and bind to the well-known address for the service offered. Leave the socket unconnected 4 Master: Repeatedly receive the next request from a client, and create a new slave thread to handle the response 4 Slave: Receive a request and access to a socket on creation 4 Slave: Form a reply and send it back to the client 4 Slave: Exit. (slave thread terminates after one request)
53
Concurrent connection-oriented server 4 Master: Create a socket and bind to the well-known address for the service offered. Leave the socket unconnected 4 Master: Place the socket in passive mode 4 Master: Repeatedly accept the next request from a client, and create a new slave thread to handle the response 4 Slave: Receive a connection request (socket) upon creation 4 Slave: Interact with the client using the connection; receive requests and send replies 4 Slave: Close connection and exit. Slave thread exits after handling all requests from one client.
54
Server summary 4 Iterative, connectionless server –Good for trivial processing per request 4 Iterative, connection-oriented server –Good for trivial processing per request where reliable transport is required. –Overhead of establishing and terminating a tcp session can impact response time 4 Concurrent, connectionless server –Unusual choice –New thread created for each request, not each client –OK if time to service a request is substantially greater than the time to create a thread 4 Concurrent, connection-oriented –Most general type of server –Reliable transport –Multiple concurrent clients
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.