正在加载图片...
Iterative connectionless server Forming a reply address in a algorithm connectionless server Creating a socket and bind to the well a Can not use connect known address for the service being Uses an unconnected socket Uses sendto to send datagram 2. Repeatedly receive the next request from the client, formulate a response and send a reply back to the clien mber of by according to application-protocol contains data contains the control options ( endpoint addr Forming a reply address in a Concurrent connectionless server connectionless server algorithm Easy way to obtain address of client Master 1: Creating g socket and bind to the well- From source address found in request next d to handle the response. t and create a new slave place next datagram Slave 3: Exit(i. e. a slave thread terminates after control options Few connectionless servers have concurrent implementation Concurrent connection-oriented Apparent Concurrency using a server algorithm gle thread Ma known Cdertes for e service beia ofed Creating a socket and bind to the well-known Leaving the socket unconnected. Add socket to the list Master 2: Place the socket in passive mode, making it se select to wait for I/O on existing sockets tedly call accept to receive the next reate a new slave Id the new socket to hread to handle the response hich I/O is possible Slave 1: Receive a connection request (i. e, socket for receive request(s) k to the clie and exit. The slave Continue processing with step 2 above. read exits after ng all requests from one3 哈工大计算机学院 李全龙 Network Application Development Server Software Design 13 Iterative connectionless server algorithm 1. Creating a socket and bind to the well￾known address for the service being offered. 2. Repeatedly receive the next request from the client, formulate a response, and send a reply back to the client according to application-protocol. 哈工大计算机学院 李全龙 Network Application Development Server Software Design 14 Forming a reply address in a connectionless server „ Can not use connect „ Uses an unconnected socket „ Uses sendto to send datagram retcode=sendto(socket,data,length,flags,destaddr,addrlen); unconnected socket address of a buffer that contains data to be sent number of bytes in the buffer Debugging or control options Pointer to a sockaddr_in structure that contains the endpoint address Length of the address structure 哈工大计算机学院 李全龙 Network Application Development Server Software Design 15 Forming a reply address in a connectionless server „ Easy way to obtain address of client „ From source address found in request „ Use recvfrom retcode=recvfrom(socket,buf,length,flags,from,fromlen); a socket to use address of a buffer place next datagram Space available in the buffer Debugging or control options Address of the second buffer place the source address Length of the source address 哈工大计算机学院 李全龙 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. 哈工大计算机学院 李全龙 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. 哈工大计算机学院 李全龙 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
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有