On the differences between the WebSocket and Socket

Surely we do instant messaging service or need replacement in rotation when the WebSocket and Socket certainly heard these two things, we have to say today about the simple difference between the two.

What is WebSocket

WebSocket protocol is a full duplex communication over a single TCP connection. WebSocket enables exchange of data between the client and the server easier, allowing the server actively push data to the client. In the WebSocket API, the browser and the HTTP server only needs to complete a handshake, you can directly create a persistent connection between the two, and two-way data transmission.

Why have HTTP need WebSocket?

Under normal circumstances we use HTTP has a big drawback, HTTP is the only side to take the initiative launched by the client, if the server business needs proactive notification, you need training in rotation. Inefficient polling, is a waste of resources. In order to address the needs of end Web instant messaging appeared WebSocket.

WebSocket (2) - Why introduced WebSocket protocol

compatibility

WebSocket is the first part of the HTML5 standard, the basic modern browsers are supported, it can be used directly. Although it is part of HTML5, but outside of the browser also has a corresponding implementation. For example Socket.io The library supports Java, C ++, Swift, Datr , Python 's ws4py, C ++'s WebSocket ++ and so on.
Mainstream Web server containers such as Apache, Nginx, Tomcat also supports WebSocket, as well as WebSocket server-side frameworks such as websocketd and so on.

What is Socket

The Unix Socket

Operating systems are also used to the concept of Socket used for inter-process communication, and it is often said that the concept based on Socket TCP / IP are very similar, both on behalf of the operating system, transmission of data, but it is no longer based network protocol , but the operating system itself file system.

Network Socket

Socket not a network protocol, but for the use of TCP, UDP and abstract layer API, which is an abstraction layer between the application layer and the transport layer is between. Socket is the encapsulation of a TCP / IP; the HTTP passenger car, a particular form of packaging or display data; Socket engine, provides the ability to network communications. Under Unix everything is a file philosophical thought, Socket is a kind of "open - Read / Write - Off" mode of implementation, server and client are maintained a "file" in the open after the connection is established, you can write to your own file content for each other or read each other to read the contents, close the file at the end of the communication. So if you want to build services based on TCP / IP, Socket API so that you may be exposed to the API.

WebSocket and the difference between Socket

As we mentioned above:

  1. Socket Interface is the transmission control layer. The user can operate the underlying TCP / IP protocol suite communicate via Socket.
  2. WebSocket is a complete application-layer protocol.
  3. Socket more flexible, WebSocket easier to use.
  4. Both can do instant messaging

Reproduced

Guess you like

Origin blog.csdn.net/P876643136/article/details/90142150
Recommended