The TCP client algorithm 1. Find the IP address and protocol port number of the server with which communication is desired 2. Allocate a socket 3. Specify that the connection needs an arbitrary unused protocol port on the local machine, and allow TCP to choose one Connect the socket to the server 5. Communicate with the server using the application-layer protocols 6. Close the connection 哈工大计算机学院李全龙 Network Application Development Client Software Desi
哈工大计算机学院 李全龙 Network Application Development Client Software Design 16 The TCP client algorithm 1. Find the IP address and protocol port number of the server with which communication is desired. 2. Allocate a socket. 3. Specify that the connection needs an arbitrary, unused protocol port on the local machine, and allow TCP to choose one. 4. Connect the socket to the server. 5. Communicate with the server using the application-layer protocols. 6. Close the connection
Allocating a socket #ⅰ nclude< winsock. h> SOCKET, s=socket(PF_ INET, SOCK_ STREAM, o) 哈工大计算机学院李全龙 Network Application Development Client Software Desi
哈工大计算机学院 李全龙 Network Application Development Client Software Design 17 Allocating a socket #include <winsock.h> SOCKET s; s=socket(PF_INET, SOCK_STREAM, 0 );
Choosing a local protocol port number The client does not care which port it uses as long as The port does not conflict with the ports that other applications on the machine are already usIn The port has not been assigned to a well-known service The choice of a local port that meets the criteria listed above happens as a side- effect of the connect call 哈工大计算机学院李全龙 Network Application Development Client Software Desi 18
哈工大计算机学院 李全龙 Network Application Development Client Software Design 18 Choosing a local protocol port number The client does not care which port it uses as long as : The port does not conflict with the ports that other applications on the machine are already using. The port has not been assigned to a well-known service. The choice of a local port that meets the criteria listed above happens as a sideeffect of the connect call
Choosing a local IP address a client must choose a local ip address as well as a local port number Gateways(routers)or multihomed hosts have multiple ip addresses The difficulty in choosing an iP address arises because the correct choice depends on routing and applications seldom have access to routing ormation Problem: the ip source address in an outgoing datagram should match the Ip address of the 已 network interface over which IP routes the datagram Using an incorrect address violates the specification makes network management difficult and confusing and makes the program less reliable 已. 哈工大计算机学院李全龙 Network Application Development Client Software Desi
哈工大计算机学院 李全龙 Network Application Development Client Software Design 19 Choosing a local IP address A client must choose a local IP address as well as a local port number. Gateways (routers) or multihomed hosts have multiple IP addresses. The difficulty in choosing an IP address arises because the correct choice depends on routing and applications seldom have access to routing information. Problem: the IP source address in an outgoing datagram should match the IP address of the network interface over which IP routes the datagram. Using an incorrect address violates the specification, makes network management difficult and confusing, and makes the program less reliabl e
Choosing a local IP address To solve the problem the socket functions make it possible for an application to leave the local IP address field unfilled and to allow TCP/ IP software to choose a local IP address automatically at the time the client connects to a server Because choosing the correct local Ip address requires the application to interact with IP routing software, TCP client software usually leaves the local endpoint address unfilled, and allows TCP/IP software to select the correct local IP address and an unused local protocol port number automatically 哈工大计算机学院李全龙 Network Application Development Client Software Desi
哈工大计算机学院 李全龙 Network Application Development Client Software Design 20 Choosing a local IP address To solve the problem, the socket functions make it possible for an application to leave the local IP address field unfilled and to allow TCP/IP software to choose a local IP address automatically at the time the client connects to a server. Because choosing the correct local IP address requires the application to interact with IP routing software, TCP client software usually leaves the local endpoint address unfilled, and allows TCP/IP software to select the correct local IP address and an unused local protocol port number automatically