Iterative connection-oriented server algorithm Creating a socket and bind to the well-known address for the service being offered Place the socket in passive mode, making it ready for use by a server Accept the next connection request from the socket, 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 according to application-protocol 5. When finished with a particular client, close the connection and return to step 3 to accept a new connection 哈工大计算机学院李全龙 Network Application Development Server Software Design 11
哈工大计算机学院 李全龙 Network Application Development Server Software Design 11 Iterative connection-oriented server algorithm 1. Creating a socket and bind to the well-known address for the service being offered. 2. Place the socket in passive mode, making it ready for use by a server. 3. Accept the next connection request from the socket, 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 according to application-protocol. 5. When finished with a particular client, close the connection and return to step 3 to accept a new connection
Binding to a well-known address 國 y using INADDR ANy bind uses structure sockaddr Selecting a specific IP address at which a server will accept connections can cause difficulty especially for gateways (routers) Special constant: INADDR_ ANy Wildcard address Servers use Inaddr any instead a specifⅰ c IP address 哈工大计算机学院李全龙 Network Application Development Server Software Desi
哈工大计算机学院 李全龙 Network Application Development Server Software Design 12 Binding to a well-known address by using INADDR_ANY bind uses structure sockaddr_in Selecting a specific IP address at which a server will accept connections can cause difficulty especially for gateways (routers) Special constant: INADDR_ANY Wildcard address Servers use INADDR_ANY instead a specific IP address
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 13
哈工大计算机学院 李全龙 Network Application Development Server Software Design 13 Iterative connectionless server algorithm 1. Creating a socket and bind to the wellknown 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
Forming a reply address in a op connectionless server Can not use connect Uses an unconnected socket Uses sendto to send datagram recode=sendto (socket, data, length, flags, destaddr, addrlen) unconnected socket Pointer to a number of bytes sockaddr in address of a buffer in the buffer structure that that contains data contains the to be sent Debugging or endpoint address control options Length of the address structure 哈工大计算机学院李全龙 Network Application Development erver software desi
哈工大计算机学院 李全龙 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
Forming a reply address in a op connectionless server Easy way to obtain address of client From source address found in request Use recvfrom recode=recvfrom(socket, buf, length, flags, from, fromlen)i a socket to use Space available Address of address of a buffer in the buffer the second buffer place place next datagram Debugging or the e source control options address Length of the source address 哈工大计算机学院李全龙 Network Application Development Server Software Design 15
哈工大计算机学院 李全龙 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