Unformatted text preview:

Client-Server CommunicationsUniversal Internet Communication Interface (UICI)Network ApplicationsConnectionless ProtocolConnection-Oriented ProtocolNaming of ServersSingle Port StrategySingle Port ProblemsConnectionless ProtocolSerial-Server StrategySerial-Server PseudocodeParent-Server StrategyParent-Server PseudocodeThread-Server StrategyUICI Summarycopy_from_network_to_fileSerial ServerParent-Server (top)Parent-Server (bottom)Client (top)Client (bottom)UICI Implementationu_read an u_writeOpen Systems Interconnection (OSI)Peer-to-Peer OSI ModelPhysical/Data-Link LayersNetwork LayerTransport LayerTransport Layer PortsSession LayerPresentation/Application LayersOSI DrawbacksSocketsSocket ServerSocket ClientSocket Communicationssocketbindbind (continued)struct sockaddrstruct sockaddr_inlistensin_port fieldu_openu_open socket Implementationacceptgethostbyaddru_listen socket Implementationconnectgethostbynameu_connect socket Implementation (top)u_connect Implementation (bottom)Client-Server Communications• Servers provide services to clients over a network• Most LANs have file servers to manage common disk space• This makes it easier to share files and perform backups• Mail and ftp use client-server paradigmUniversal Internet Communication Interface (UICI)• Simplifies client-server programming• UICI is implemented in this chapter with SocketsNetwork Applications• ftp – file transfer• Kerberos – authentication• telnet – remote login• NFS – remote filesystemsConnectionless Protocol• The client sends a single message to the server• The server performs a service and sends a replyConnection-Oriented Protocol• Server waits for a connection request from a client• Once the connection is established, communication takes place using handles (file descriptors)• The server address is not included in the user message• Connection-oriente protocol has setup overhead• This chapter emphasizes connection-oriented protocolNaming of Servers• Option 1 – Designate server by process ID and host ID– Process ID is assigned chronolocically at the time process starts running– It is difficult to know process ID in advance on a host• Option2 – Name servers with small integers called ports– Server “listens” at a well-known port that has been designated in advance for a particular service– Client explicitly specifies a host address and a port number on the host when setting up a connectionSingle Port StrategyServerClient Requests• Simplest client-server communication takes place over a single communication port• If client and server are on the same machine, the single port can be a FIFO• On a network port can be socket or TLI connection• When server starts up, it opens FIFO (or Socket) and waits for client requests• When client needs service, it opens FIFO (or Socket) and writes its request• Server then performs the serviceSingle Port Problems• There is no mechanism for the server to respond to the client• Since items are removed from the port when they are read, there is nothing to prevent one client from taking another’s requestConnectionless ProtocolServerClient RequestsClientClientServer ResponsesServer Responses• Each client has its own channel for receiving responses from the server• sendto and receivefrom form the basis of connectionless protocolSerial-Server StrategyClient RequestServer ClientTwo-Way Communication• Two way channel is for additional interaction between client and server• Initial client request serves to establish two way communication channel• Communication channel is private – not accessable to other processes• A busy server handling long-lived requests cannot use serial server strategySerial-Server Pseudocodefor (;;) {listen for client request;create private two-way communication channel;while (no error on communication channel)read client request;handle request and respond to client;close communication channel}Parent-Server StrategyClient RequestServer ClientTwo-Way Communication• Server forks a child to handle actual service• Server resumes listing for more requests• Similar to switchboard at hotel• Server can accept multiple client requestsforkServerChildParent-Server Pseudocodefor (;;) {listen for client request;create a private two-way communication channel;fork a child to handle the request;close the communication channel;clean up zombies;}Thread-Server StrategyClient RequestServerThreadsClientTwo-Way Communication• Low overhead alternative to parent-server strategy• Create thread to handle request instead of forking child –threads have less overhead• Efficient if request is small or I/O intensive• Possible interference among multiple requests due to shared address space• For computationally intensive services, additional threads may reduce efficiency of or block the main server thread• Requires good kernel-level parallelismUICI SummaryUpdates relevant kernel info afger calls to execint u_sync(int fd)Outputs errmsg followed by a UICI error messagevoid u_error(char *errmsg)Writes nbyte bytes from buf to fd. Returns number of bytes writtenssize_t u_write(int fd, char *buf,size_t nbyte)Reads up to nbyte bytes from fd into buf. Returns number of bytes actually readssize_t u_read(int fd, char *buf,size_t nbyte)Closes file descriptor fdint u_close(fd)Initiates connection to server on port port and host the_host. Returns communication fdint u_connect(u_port_t port,char *the_host)Listens for connection request on fd. Returns communication fdint u_listen(int fd, char *hostn)Opens file descriptor bound to port. Returns listening fdint u_open(u_port_t port)DescriptionUICI Prototypeint copy _from_network_to_file(int communfd, int filefd) {…for ( ; ; ) {if ((bytes_read = u_read(communfd, buf, BLKSIZE)) < 0) {u_error("Server read error");break;} else if (bytes_read == 0) {fprintf(stderr, "Network end-of-file\n");break;} else { /* allow for interruption of write by signal */for (bufp = buf, bytes_to_write = bytes_read;bytes_to_write > 0;bufp += bytes_written, bytes_to_write -= bytes_written){bytes_written = write(filefd, bufp, bytes_to_write);if ((bytes_written) == -1 && (errno != EINTR)){perror("Server write error");break;} else if (bytes_written == -1)bytes_written = 0;total_bytes += bytes_written; }if (bytes_written == -1)break; } } return total_bytes; }copy_from_network_to_filevoid main(int argc, char *argv[]) {u_port_t portnumber;int listenfd;int communfd;char


View Full Document

Chico CSCI 372 - Client-Server Communications

Download Client-Server Communications
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Client-Server Communications and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Client-Server Communications 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?