WebSocket is different from HTTP and WebSocket is different from Socket

Recently, I am working on an IM project, and I have a vague understanding of it. Here I make a distinction between their differences and similarities. However, since this project requires multiple platforms in IOS, Android and Web, I finally choose WebSocket.

Here is a diagram detailing the distribution of various protocols in the TCP/IP protocol family in the OSI model. One diagram is worth a thousand words.

1. WebSocket is introduced

The principle of

WebSocket is also an application-layer protocol like HTTP, but it is a two-way communication protocol built on TOP of TCP.

Connection process – Handshake process

    1. The browser and server establish a TCP connection and shake hands for three times. This is the basis of communication, the transport control layer, and if it fails, it doesn’t execute.
    1. After the TCP connection succeeds, the browser sends information such as the version number supported by WebSocket to the server through HTTP. (HTTP handshake before starting)
    1. After receiving the handshake request from the client, the server also uses HTTP to send back data.
    1. After receiving a successful connection message, communication is transmitted through the TCP channel

2. WebSocket in HTTP

The same

    1. Both are application layer protocols that transmit data based on TCP, both are reliability transmission protocols.
    1. Both are application layer protocols.

The difference between

    1. WebSocket is a two-way communication protocol that simulates the Socket protocol and can send or receive information in both directions. HTTP is one-way.
    1. WebSocket requires a handshake to establish a connection.

contact

When WebSocket establishes a handshake, data is transmitted over HTTP. However, once established, the HTTP protocol is not required for actual transmission.

3. Relationship between WebSocket and Socket

Socket is not a protocol, but to facilitate the use of TCP or UDP abstract layer, is located in the application layer and transmission control layer between a set of interfaces, it works in the OSI model session layer (layer 5), It is an abstraction layer that allows you to use lower-level protocols (typically TCP or UDP) directly.

Socket is the intermediate software abstraction layer of communication between application layer and TCP/IP protocol family. It is a group of interfaces. In the design mode, Socket is actually a facade mode, it hides the complex TCP/IP protocol family behind the Socket interface, for the user, a simple set of interfaces is all, let the Socket to organize data to conform to the specified protocol.

When two hosts communicate with each other, they must be connected through a Socket, which uses TCP/IP to establish a TCP connection. TCP connections rely on the underlying IP protocol, and IP connections rely on the link layer and other lower layers.

The difference between

Socket is a transport control layer protocol, and WebSocket is an application layer protocol.

Star my lot

# Back