сокет – What is the difference between socket and websocket?

Question:

I realized that a socket is roughly speaking a socket-interface (as computer IP and port parameters) that a program creates through which another computer can connect to it by specifying the same address and port. And then web sockets loomed. What is the difference between them?

Answer:

Socket is really a programming interface . This is an abstract concept, which, in most cases, is used to communicate programs on the network (but not only).

WebSocket is a protocol (some predetermined order) for exchanging data (like http, ftp, ssl, etc.). This protocol goes over (transferred by) the TCP protocol.

Socket and WebSocket are different concepts in principle. When working with the WebSocket protocol, you will use regular sockets to connect. As well as when working with other protocols, sockets will be used (and for working with http, ftp, etc.).

For example, consider a string like – ws://127.0.0.1:15000. In it, ws is exactly an indication that the WebSocket protocol will be used when exchanging data. 127.0.0.1 – ip address of the computer, 15000 – port to which the connection is made. So 127.0.0.1:15000 – this pair, so to speak, is a socket.

The WebSocket protocol was created in order to be able to maintain long-lasting, unbreakable connections between a browser (which is a client) and a website (which is a server).

The WebSocket protocol is not like HTTP. The only way it resembles HTTP is only with one very first connection request (the so-called handshake / handshake). This was done because the protocol was originally designed to work in the browser and it was necessary to determine the possibility of supporting it. Once the connection is established, nothing like the HTTP protocol in the WebSocket protocol is even close.

The WebSocket protocol itself does not guarantee any security for transmitted data. The minimum encoding that it provides is a banal XOR (XOR). In this case, the mask for the xorca is transmitted along with the message. And this xorka is designed to transfer data through proxy servers that do not know anything about the WebSocket protocol. This is not the protection of your data – this is the protection of a proxy server. And in the opposite direction (from the site to the browser), the data is not encoded by Xorca, due to the lack of need.

It is the absence of any bells and whistles in the WebSocket protocol that gives it the ability to work quickly.

Scroll to Top