Network programming is the writing of multiple computers networked interactive data. The operating system will provide a part called socket (socket), socket is the network data transmission device software, so that network programming can also become socket programming.
In this borrowing book call example, the use of the socket to do a simple description:
1) First, a phone call, a new phone is equivalent to creating a telephone socket.
int socket (int domain, int type, int protocol);
2) Assign a number to the phone, bind the IP address and port number.
int bind (int sockfd, struct sockaddr* myaddr, socklen_t Addrlen);
After calling the Bind method to assign an address (IP, port number) to the socket, it completes the creation of the socket, and the next thing to do is to link the socket as needed.
3) connect the phone (socket) so that it can communicate with the phone and set the socket status to receive status.
int listen (int sockfd, int backlog);
4) Set the phone status, when there is a telephone access, the socket calls the Accept method, when there is a link to the request (there is a call, that is, a different program to link), to accept (socket communication).
int accept (int sockfd, struct sockaddr* addr, socklen_t* Addrlen);
TCP/IP Programming Learning 01