TCP Client Algorithm Find the Ip address and protocol port number of the server 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-level protocol 6. Close the connection CSIE NTUT Taiwan 16
CSIE, NTUT, Taiwan 16 TCP Client Algorithm 1. Find the IP address and protocol port number of the server 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-level protocol 6. Close the connection
Allocating a socket TCP is specified by protocol family PF INET and service SOCK sTreaM a Recall the system call, socket, which has three arguments int socket(int domain int type, int protocol) Example #include <sys /types. h> #includesys/socket. h> Int s s=socket(PF INET, SOCK STREAM, 0) CSIE NTUT Taiwan 17
CSIE, NTUT, Taiwan 17 Allocating a Socket ◼ TCP is specified by protocol family PF_INET and service SOCK_STREAM ◼ Recall the system call, socket(), which has three arguments int socket(int domain, int type, int protocol); ◼ Example: #include <sys/types.h> #include<sys/socket.h> int s s=socket (PF_INET, SOCK_STREAM, 0)
TCP Client Algorithm Find the Ip address and protocol port number of the server 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-level protocol 6. Close the connection CSIE NTUT Taiwan
CSIE, NTUT, Taiwan 18 TCP Client Algorithm 1. Find the IP address and protocol port number of the server 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-level protocol 6. Close the connection