WebSocket
- taolius
- Feb 6, 2017
- 1 min read
https://blog.idrsolutions.com/2013/12/websockets-an-introduction/
Another good example : https://dzone.com/articles/websockets-spring-4
What is WebSocket?
WebSocket is a protocol which allows for communication between the client and the server/endpoint using a single TCP connection. Sounds a bit like http doesn’t it? The advantage WebSocket has over HTTP is that the protocol is full-duplex (allows for simultaneous two-way communcation) and it’s header is much smaller than that of a HTTP header, allowing for more efficient communcation even over small packets of data.
The life cycle of a WebSocket is easy to understand as well:
Client sends the Server a handshake request in the form of a HTTP upgrade header with data about the WebSocket it’s attempting to connect to.
The Server responds to the request with another HTTP header, this is the last time a HTTP header gets used in the WebSocket connection. If the handshake was successful, they server sends a HTTP header telling the client it’s switching to the WebSocket protocol.
Now a constant connection is opened and the client and server can send any number of messages to each other until the connection is closed. These messages only have about 2 bytes of overhead.
Commentaires