The socket is translated as a "communication node" in computer jargon. The computer network illustrates that communication between computers is often referred to as communication between applications. And the application between the use of sockets to communicate, it can be simple to think that the socket encapsulates the implementation of the TCP/IP protocol, we can use the high-level computer language in an abstraction layer to achieve computer communication, without regard to specific details.
The most common form of communication is the client-server form, we open the Internet browser, login QQ Chat, this is the form. Browser/QQ is the client, and the website is the Web server, QQ Chat server is the service side.
The service side listens to a port through the socket, and contracts the protocol, the client establishes the connection through the socket and the server, then communicates through the specific protocol and the service side.
in the case of a Web server, it starts, listens on port 80, and contracts with the HTTP protocol. When the browser accesses the Web server, establishes a connection, sends an HTTP request, the Web server processes the request, and returns the content. After the browser receives the return information, it renders in the browser and disconnects.
The connection mentioned above is actually a socket connection, because it is implemented using a socket. It is important to note that the above process is the simplest form, the server can not actively send data to the client, once the request is completed, the connection is disconnected.
at some point, the socket connection is established and will remain, such as a chat app. When QQ and chat server establish a connection, the client can send a message to the server, when there are new messages, the server can also proactively push messages to the client. The connection will not be broken unless the user exits QQ, which is the long socket connection. And we usually see between Web servers and browsers called short connections.
What the hell is a socket.