Jos de Jong
Jos de Jong

Reputation: 6819

Is there a way to send meta data when opening a WebSocket?

I'm looking for a way to send a unique identifier to the server when opening a WebSocket.

I could implement this by sending an handshake message after being connected, but it would be very nice if that wasn't needed and instead I could just send and read the identifier via meta data, similar to header fields in http requests.

Is there a way to send meta data when opening a WebSocket?

Upvotes: 3

Views: 2819

Answers (1)

levi
levi

Reputation: 25091

The WebSocket connection is initiated via an HTTP GET request. So you can include meta-data in the GET headers, like you would for any other request. Alternatively, you can append some params in the query string of the ws endpoint: ws://site.com/stream?param=foo, and parse the data on the server-side (will be received as a GET request).

See here

Upvotes: 5

Related Questions