DOC PREVIEW
U of I CS 241 - UICI Communication (II)

This preview shows page 1-2-3-4-5 out of 16 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS241 System Programming UICI Communication (II)ContentAdministrative CommentsUniversity Internet Communication Interface (UICI)UICI: A simple connection-oriented client-server implementationUICI: A simple connection-oriented client-server implementationUICI Commands for Client-Server InteractionUICI LibrarySocket Implementation of UICIHandling Errors and Information ExchangeUICI Implementation of Different Server StrategiesUICI Implementation of Server Listening to Passive Port (Code from Program 18.1)Server Listening, Creating Process for Communication (Code from Program 18.2)UICI Client Code (Code from Program 18.3)Compiling network code under Linux and SolarisSummaryCS241 System Programming UICI Communication (II)Klara NahrstedtLecture 354/17/2006Contentz Universal Internet Communication Interface (UICI)– Goal of UICI– Interaction of UICI client and server– UICI APIs– Handling errors– UICI Implementation of Server Strategies– UICI Clients– Relation to SocketsAdministrative Commentsz Deadline for MP4, April 18z MP5 starts this week, deadline May 1z Quiz 10, Friday, April 21– Covers T: 4.3, 4.4.1-4.4.6 and 4.5.1-4.5.3z This week, we will cover R&R Chapter 18 and 20University Internet Communication Interface (UICI)z Provides a simplified interface to connection-oriented communication in UNIXz NOT part of any UNIX standardz Designed by Robins and Robins authors to hide details of underlying network protocolsz We will use UICI in MP5 so you must upload uici.h(see MP5 instructions) TCP/IP and UDP/IP ProtocolsUICI InterfaceAPPLICATION CODE SOCKET InterfaceWe will use thisinterface.UICI: A simple connection-oriented client-server implementationThe server does the following: z open a well-known listening port and obtain a listening file descriptor (fd) from the portz wait for a connection request from the client on that listening fdz when a request comes in, return a communication file descriptor (to use as a handle for private, two-way client-server communication)z the server handles the connection by reading or writing using the communication file descriptor z this can be done serially, or by a child while the parent is waiting for another requestUICI: A simple connection-oriented client-server implementationA client does the following: z request a connection to a particular port on a particular server host z if successful, server returns a communication file descriptor for communication z communicates by doing reads and writes on this file descriptor z close the communication file descriptorUICI Commands for Client-Server Interaction Create communicationEndpoint via u_connect-Create communicationEndpoint via u_accept-Get private communicationFile descriptorUICI LibraryUICI Prototype Descriptionint u_open(u_port_tport)Creates a TCP socket bound to port and sets the socket to be passive. Returns a file descriptor for the socket.int u_accept(int fd, char *hostn, inthostnsize)Waits for connection request on fd.On successful return, hostn has the first hostnsize-1characters of the client's host name.Returns a communication file descriptor. int u_connect(u_port_tport, char *hostn)Initiates a connection to server on port port and host hostn.Returns a communication file descriptor.Socket Implementation of UICIUICI Sockets actionsocketcreate communication endpointbindassociate endpoint with a specific portlistenmake endpoint passive listeneru_accept acceptaccept connection request from clientsocketcreate communication endpointconnectrequest connection from serveru_connectu_openAll socket system calls return -1 and set errno.Handling Errors and Information Exchangez Error HandlingAll UICI routines return -1 on error with errno set. z Reading and writing– After a connection is set up between the client and the server, read and write can be used. – It is recommended that you use r_read and r_writeinstead. These behave better in the presence of signals and r_write will write the number of bytes requested or return an error. – When doing network communication, it is not unusual for a write call to return with fewer bytes written than requested.UICI Implementation of Different Server Strategiesz Example shows client sending text to server1. Server listening to port2. Server listening to port creating processes to communicate3. Client accessing portUICI Implementation of Server Listening to Passive Port (Code from Program 18.1)… /* initialize */11 portnumber = (u_port_t) atoi(argv[1]);12 …listenfd = u_open(portnumber)) …18 for ( ; ; ) {19 … communfd = u_accept(listenfd, client, MAX_CANON)) …24 bytescopied = copyfile(communfd, STDOUT_FILENO);26 … r_close(communfd) …27 }… /* cleanup */11 Get a port number in network byte order12 Open port for requests at port address19 Get a request for a communication and open communication port24 Copy all the bytes from the communication26 Close communication portServer Listening, Creating Process for Communication (Code from Program 18.2)…22. portnumber = (u_port_t) atoi(argv[1]);23. … u_open(portnumber)) 30. … u_accept(listenfd, client, MAX_CANON))35. … child = fork())38. … r_close(listenfd)42. … copyfile(communfd, STDOUT_FILENO);46. … r_close(communfd)49. … r_waitpid(-1, NULL, WNOHANG) 35. Create a child38. Main process closes listening port42. Child process copies data from communication port46. Child process closes communication port49. Main process makes sure no children are around when it finishesUICI Client Code (Code from Program 18.3)14. portnumber = (u_port_t)atoi(argv[2]);15. …u_connect(portnumber, argv[1])) 19. …copyfile(STDIN_FILENO, communfd);14. Converts port to network byte order15. Asks for server port through passive server port number16. Copies all of data from input to remote port.Compiling network code under Linux and Solarisz To compile network code under Linux, include the nsl library by putting -lnsl at the end of the compile line as in:cc -o server server.c restart.c uici.cuiciname.c -lnslz To compile under Solaris, you also need to include the socket library:cc -o server server.c restart.c uici.cuiciname.c -lnsl -lsocketSummaryz Client-Server Process Communication – Communication Channel– Communication Protocols – Connectionless vs Connection-oriented– Connection-oriented Server


View Full Document

U of I CS 241 - UICI Communication (II)

Documents in this Course
Process

Process

28 pages

Files

Files

37 pages

File I/O

File I/O

52 pages

C Basics

C Basics

69 pages

Memory

Memory

23 pages

Threads

Threads

14 pages

Lecture

Lecture

55 pages

C Basics

C Basics

24 pages

Signals

Signals

27 pages

Memory

Memory

45 pages

Threads

Threads

47 pages

Threads

Threads

28 pages

LECTURE

LECTURE

45 pages

Threads

Threads

30 pages

Threads

Threads

55 pages

Files

Files

37 pages

SIGNALS

SIGNALS

22 pages

Files

Files

37 pages

Threads

Threads

14 pages

Threads

Threads

13 pages

Load more
Download UICI Communication (II)
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 UICI Communication (II) 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 UICI Communication (II) 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?