HTTP vs WebSocket

HTTP

WebSocket

Data transmission mechanism

It is a request-response protocol, meaning that when a client sends a request to the server, the server will return a single and brief response. After that, the connection between the client and server will close. This means that to send new data, the client will have to send a new request to the server.

It is a full-duplex protocol, meaning both the client and server can send and receive data simultaneously without having to send requests and responses one after another like HTTP. The connection between the client and server will be kept open throughout the entire session, allowing data to be sent and received directly without the need to re-establish the connection.

Establish connection

The connection is established by sending a request from the client to the server. After the server returns a response, the connection between the client and server is closed.

The connection is established using a separate protocol (WebSocket handshake protocol) to establish the connection between the client and the server. Once the connection is established, the client and server send data to each other without sending requests and responses.

Data format

Typically uses data formats such as HTML, JSON or XML to transmit data between client and server.

There is no limit to the data format used to transmit data between client and server.

Reliability

The reliability of HTTP depends on the protocol used to send data (e.g. TCP or UDP). If the network connection fails or is interrupted, data transmission over HTTP may be lost or corrupted.

WebSocket is designed to minimize connection loss or interruption

Maintain status

Stateless

Stateful

Last updated