Skip to content

Instantly share code, notes, and snippets.

View suspense-dev's full-sized avatar

Alex Krasnov suspense-dev

  • Moscow, Russia
View GitHub Profile
@suspense-dev
suspense-dev / format.md
Last active January 19, 2023 17:48
WebSocket messaging protocol

Draft of communication protocol on WebSocket

Handshake with WebSocket

In order to switch communication protocol from HTTP to WebSocket we need to implement a "handshake". Handshake is HTTP request with certain headers which tells the server that we want to connect to it via WebSocket protocol in order to keep further communication upon it.

But the server needs to authorize anyone who wants to connect to it by WebSocket. Therefore the client needs a secret key which will be attached to handshake.

In order to get this secret key the login mechanism is supposed to use HTTP request. After we authorize with login, we get a secret key in response. This key must be used in the "handshake" to let the server know that we have rights for it.

After successful "handshake" we are ready to emit and receive messages.