Concurrent connectionless server 國 algorith Master 1: Creating a socket and bind to the well known address for the service being offered Leaving the socket unconnected Master 2: Repeatedly call recvfrom to receive the next request from a client and create a new slave thread fo handle the response Slave 1: Receive a specific request upon creation as well as access to the socket Slave 2 Form a reply according to the app-protocol and send it back to the client using sendto Slave 3: Exit(i.e, a slave thread terminates after handling one request Few connectionless servers have concurrent implementations 哈工大计算机学院李全龙 Network Application Development Server Software Design 16
哈工大计算机学院 李全龙 Network Application Development Server Software Design 16 Concurrent connectionless server algorithm Master 1: Creating a socket and bind to the well- known address for the service being offered. Leaving the socket unconnected. Master 2: Repeatedly call recvfrom to receive the next request from a client, and create a new slave thread to handle the response. Slave 1: Receive a specific request upon creation as well as access to the socket. Slave 2: Form a reply according to the app- protocol and send it back to the client using sendto. Slave 3: Exit(i.e., a slave thread terminates after handling one request) Few connectionless servers have concurrent implementations
Concurrent connection-oriented server algorithm Master 1: Creating a socket and bind to the well known address for the service being offered Leaving the socket unconnected Master 2: Place the socket in passive mode, making it ready for use by a server Master 3: Repeatedly call accept to receive the next request from a client and create a new slave thread to handle the response Slave 1: Receive a connection request (i.e., socket for the connection)upon creation Slave 2: Interact with the client using the connection receive request(s and send back response(s Slave 3: Close the connection and exit. the slave thread exits after handling all requests from one client 哈工大计算机学院李全龙 Network Application Development Server Software Design 17
哈工大计算机学院 李全龙 Network Application Development Server Software Design 17 Concurrent connection-oriented server algorithm Master 1: Creating a socket and bind to the well- known address for the service being offered. Leaving the socket unconnected. Master 2: Place the socket in passive mode, making it ready for use by a server. Master 3: Repeatedly call accept to receive the next request from a client, and create a new slave thread to handle the response. Slave 1: Receive a connection request (i.e., socket for the connection) upon creation. Slave 2: Interact with the client using the connection: receive request(s) and send back response(s). Slave 3: Close the connection and exit. The slave thread exits after handling all requests from one client
Apparent Concurrency using a single thread Creating a socket and bind to the well-known address for the service, Add socket to the list of those on which i/O is possible 2. Use select to wait for I/o on existing sockets If original socket is ready use accept to obtain the next connection and add the new socket to he list of those on which I/O is possible 4. If some socket other than the original is ready, use recy to obtain the next request form response, and use send to send the response back to the client 5. Continue processing with step 2 above 哈工大计算机学院李全龙 Network Application Development Server Software Design 18
哈工大计算机学院 李全龙 Network Application Development Server Software Design 18 Apparent Concurrency using a single thread 1. Creating a socket and bind to the well-known address for the service. Add socket to the list of those on which I/O is possible. 2. Use select to wait for I/O on existing sockets. 3. If original socket is ready, use accept to obtain the next connection, and add the new socket to the list of those on which I/O is possible. 4. If some socket other than the original is ready, use recv to obtain the next request, form response, and use send to send the response back to the client. 5. Continue processing with step 2 above
Chapter 4: Server Software Design Chapter goal: Algorithm and issues Iterative servers Concurrent connection-oriented servers Singly-threaded, concurrent servers Multiprotocol servers Multiservice servers Uniform, efficient management of server concurrency 哈工大计算机学院李全龙 Network Application Development Server Software Desi
哈工大计算机学院 李全龙 Network Application Development Server Software Design 19 Chapter 4: Server Software Design Chapter goal: Algorithm and issues Iterative servers Concurrent, connection-oriented servers Singly-threaded, concurrent servers Multiprotocol servers Multiservice servers Uniform, efficient management of server concurrency
Creating a Passive Socket Use procedures to hide the details Two high-level procedures passiveUDP passive TCP The low-level procedure: passivesock 哈工大计算机学院李全龙 Network Application Development Server Software Design 20
哈工大计算机学院 李全龙 Network Application Development Server Software Design 20 Creating a Passive Socket Use procedures to hide the details Two high-level procedures: passiveUDP passiveTCP The low-level procedure: passivesock