0

So there is a limit of 1 websocket connection per webpage in most browsers. Therefore, if I want my application to update several different items on a single page at the same time, I need to pass name/value pairs, e.g.:

number_of_notifications=5
latest_news_headline='Websockets are awesome!'
foo='bar'

My question is: what is the best cross-browser way to do this? The problem with simply sending variables as I showed above and then splitting them based on the '=' sign is that an equal sign in either the name or the value can break the script:

latest_news_headline='Websockets = awesome!'

My first thought was to transmit the name and value in base64 (in which case, I can use the = sign to delimit the data). Unfortunately, that's not supported in all browsers (I know that websockets aren't either, I'm actually using SockJS as a websocket emulator for the other browsers; the SockJS protocol, however, is identical to the websocket protocol, by design).

2
  • Why do you believe there is such limitation? Commented Apr 17, 2014 at 22:59
  • This may not be a physical limitation with the WebSocket protocol, but all browsers I'm aware support no more than 2 Websocket connections. Commented May 15, 2014 at 17:29

1 Answer 1

2

It seems like stringified JSON is the obvious choice?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.