WebSockets
WebSockets is a communication protocol, providing full-duplex messages, streaming on top of a Transport Control Protocol (TCP). It is standardized by the W3 organizations and it is present on all major browsers (Internet Explorer must be at version 11+). WebSockets enables the communication between a browser and a server and between our module and a server. Through the server, the data from the ESP8266 can arrive in a browser. Another big advantage for WebSockets is the bidirectional communication without creating a new request. Every communication is done on the opened TCP connection.
Protocol details
A WebSocket connection starts as an HTTP connection with the request to upgrade to a websocket
protocol.
In this case, the client is sending:
GET /chat HTTP/1.1Host: server.example.comUpgrade: websocketConnection: UpgradeSec-WebSocket-Key: t3JJHjbGL5EzHkh8GBMXGw==Sec-WebSocket-Protocol: chat, superchatSec-WebSocket-Version: 13Origin: http://example.com
And if the server is websocket
...