The original meaning of the socket is "hole" or "socket". Here as a 4BDS UNIX process communication mechanism, take the latter meaning. The socket is very similar to a telephone socket. Take a national telephone network for example. Telephone calls are equivalent to each other 2 processes of communication, the area code is its network address, a unit in the area of the switch equivalent to a host, the host assigned to each user's internal number is equivalent to the socket number. Any user prior to the call, first to occupy a telephone, equivalent to the application of a socket, and to know the other person's number, equivalent to the other side has a fixed socket. Then dial the call to the other side, which is equivalent to sending a connection request (if the other person is not in the same zone, and dial the other area code, equivalent to the network address). If the other party is present and free (equivalent to another host of communication and can accept the connection request), pick up the phone microphone, the two sides can officially call, the equivalent of successful connection. Both sides of the call process, is a direction of the telephone signal and the other from the phone to receive signals, the equivalent of sending data to the socket and receive data from the socket. After the call is over, one side hangs up the telephone equivalent of closing the socket and undoing the connection. In the telephone system, the average user can only feel the presence of the local telephone and the other phone number, the process of establishing the call, the process of voice transmission and the technical details of the entire telephone system are transparent to him, which is very similar to the socket mechanism. Socket uses the network communication facilities to achieve process communication, but it is not concerned about the details of the communication facilities, as long as the communication facilities to provide sufficient communication capacity, it is satisfied. So far, we have an intuitive description of the socket. Abstract, the socket essentially provides the endpoint of the process communication. Before a process communicates, both parties must first create an endpoint, otherwise there is no way to establish a connection and communicate with each other. Just like before the phone call, both sides must each have a telephone. Inside the net, each socket is described in a semi-relevant description: (Protocol, local address, local port) A complete socket has a local unique socket number, which is allocated by the operating system. Most importantly, the socket is designed for client/server models and provides different socket system calls for client and server programs. Customers randomly apply for a socket (equivalent to a person who wants to call can dial a call on any network phone), the system assigns a socket number; The server has a globally recognized socket, and any customer can send a connection request and information request to it ( The equivalent of a called phone has a phone number known to the caller). The socket uses client/server mode to skillfully resolve the problem of establishing a communication connection between processes. It is important that server sockets are partially related to the global. Readers may wish to consider how to establish communication between two completely random user processes. If the two sides of the communication do not have either side of the socket fixed, it is like the two sides of the phone do not know each other's phone number, to call is impossible. ----- The socket interface is the most widely used method of accessing the Internet. If you have a host that just matches the TCP/IP protocol, its IP address is 202.120.127.201, and then the FTP 202.120.127.201 is performed on another host or on the same host, apparently unable to establish the connection. The FTP service software is not running for the "202.120.127.201" host. Also, run browsing software such as Netscape on another or the same host, and enter "http://202.120.127.201" and cannot establish a connection. Now, if you run an FTP service software on this host (the software will open a socket and bind it to Port 21), run a Web service software on this host (the software will open another socket and bind it to port 80). In this way, the FTP 202.120.127.201,ftp client software is executed on another host or on the same host computer through Port 21 to call the socket provided by the FTP service software on the host, and to establish a connection and dialogue with it. When you enter "http://202.120.127.201" in Netscape, you will use 80 ports to call the socket provided by the Web Services software on the host, and to connect and talk to it. There are many such hosts on the internet that typically run multiple service software while providing several services. Each service opens a socket and is bound to a port where different ports correspond to different services. Socket, as its English intended, like a porous socket. A host is like a room full of sockets, each socket has a number, and some outlets provide 220 volts AC, some provide 110 volts AC, and some provide cable TV programs. Customer software will plug into different number of sockets, you can get different services. |