1. What is a socket? What is WebSocket?
What's the difference between the two people who have heard about WebSocket technology for the 1th time? WebSocket is the implementation of just porting the socket concept to the browser?
We know that two applications (processes) in the network need to communicate with each other at full duplex (that is, both sides can send messages to each other at the same time), the socket is needed, it can provide end-to-end communication, and for programmers, He just needs to create a socket instance at one end of an application (called a client) and provide the IP address and port it wants to connect to one end (called the server), while the other end (the server) creates another socket and binds the port to listen. Then the client connects to the server, the server accepts the connection, the two sides establish an end-to-end TCP connection, the connection can be two-way communication, and once the connection is established, there is no client service side of the communication between the two sides, providing the end-to-end communication. We can use this approach to build a desktop version of the IM program that allows users on different hosts to send messages. In essence, a socket is not a new protocol, it is simply a encapsulation of the TCP/IP protocol family communication mechanism in order to facilitate the programmer's network programming.
WebSocket is a part of the HTML5 specification, which draws on the idea of sockets, providing a full-duplex communication mechanism between the Web application client and the server side (note that the client service side). At the same time, it is a new application layer protocol, the WebSocket protocol is designed to provide a Web application and service-side full-duplex communication and a special application layer protocol, which is usually expressed as: Ws://echo.websocket.org/?encoding=text http/1.1, you can see that in addition to the previous protocol name and HTTP, its representation address is the traditional URL address.
As you can see, websocket is not simply porting the concept of sockets in a browser environment, and this article will go through a small demo to further explain the difference between the socket and the websocket in use.
WebSocket detailed (a): Preliminary understanding of WebSocket technology