tcpip - What is the difference between Socket TCP / IP, WebSockets and HTTP Request? - Stack Overflow

tcpip - What is the difference between Socket TCP / IP, WebSockets and HTTP Request? - Stack Overflow

tcpip - What is the difference between Socket TCP / IP, WebSockets and HTTP Request? - Stack Overflow

TPC / IP sockets are what make the client-server architecture possible, but are not limited to that. They are actually involved in all types of communication since they are the mechanism for delivering data packets between computers.

A socket is defined by a pair of local and remote IP addresses, a protocol transport and a pair of local and remote port numbers.

So having IP addresses and ports you can still choose which transport protocol you want to use. The transport protocol can be any one that belongs to the transport layer or layer 4. The TCP is located in this layer and the IP protocol is in layer 3. As you can see all this is very low level already that HTTP is in layer 7, the application layer, well above the sockets.

Basically you can not compare HTTP requests with sockets since the former is a specialization of the second.

As for HTTP requests and Websockets the two can be done using the HTTP protocol but are different protocols.

The WebSocket protocol is a protocol based on independent TCP. Its only relationship with HTTP is that the handshake is interpreted by HTTP servers as an Update request.

One of the reasons why this was chosen is because proxies normally block everything which is not transmitted over port 80, the default port used by HTTP. When the client (or browser usually) detects that a proxy is using the HTTP CONNECT method to create a persistent connection, otherwise use ws: // or wss: // to connect to the server. The connections with ws: // and wss: // are set to port 80 and 443 respectively, exactly the same port as http: // and https: //

Some types of communication such as a chat require that the source is always the same and it is possible to know for example if the connection was lost or its status changed. Looking at the previous conditions of the protocol is a bit complicated to achieve (although not impossible) and hence the need for a protocol such as websockets to be able to establish a stable tunnel of communication between two parties. Note that for communication to be both parties must support websockets so most frameworks today allow fallback to HTTP requests if websocket is not supported.

Some forms of replacing websockets with HTTP requests include

See larger image
Additional Images
See larger image Additional Images

Server Sent Events: Basically an HTTP request that does not end and where both parties send information (since the response part only ends when closes the connection.)

Long Pooling: A technique in which requests / responses are constantly sent at regular intervals for both parties to update the connection status and pass messages.

Comet: A set of techniques that allow you to maintain a stable connection using PUSH technology and other http techniques.

See also What are long polling websockets server sent events sse and comet

Some frameworks that implement websockets:

Note: The form of the network protocol can be so varied that it came to be invented the IP on messenger pigeons which is defined in rfc2549: P

Related news