What about WebSocket?
WebSocket takes the best of both worlds: HTTP and persistent connections.
It uses a handshake to establish communication.
The connection starts with an HTTP GET
from the client. In the request, the client specifies an upgrade to WebSocket. You can see this in the following example:
GET /chat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Origin: http://example.com
Sec-WebSocket-Protocol: chat, superchat
Sec-WebSocket-Version: 13
After the request from the client, the server can accept it, as follows:
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Sec-WebSocket-Protocol: chat
Then, the client and the server can start to exchange data until one of them decides to close the connection.
As you can see, unlike HTTP, WebSocket allows exchanging data without the need to...