Question

I have two different browsers (Chrome and Safari) on the same machine (i.e. same IP), and wonder if it is possible to connect them to the same server both using websocket?

I've tried. Chrome connects fine, but Safari throws an error, complaining:

Error during WebSocket handshake: location mismatch: 
wss://www.mysite.com/sockjs/310/s1a5r_6q/websocket != ws://www.mysite.com/sockjs/310/s1a5r_6q/websocket
sockjs-0.3.js:282Closed transport: websocket SimpleEvent(type=close, code=1006, reason=WebSocket connection broken, wasClean=false)

But I am not sure if this is due to some restriction of one websocket connection per IP address?

Was it helpful?

Solution

MLister, you seem to run into sockjs deployment issue. Make sure sockjs server returns wss:// during websocket handshake over https. This is a well-known issue with some sockjs servers - servers don't always know the page is being served over https and return ws:// during handshake.

For example, sockjs-node uses faye-websocket-node code to handle this case is here: https://github.com/faye/faye-websocket-node/blob/master/lib/faye/websocket.js#L40 https://github.com/faye/faye-websocket-node/blob/master/lib/faye/websocket.js#L25-L32

Basically, you must make sure your load-balancer sets 'x-forwarded-proto' header.

Does it make sense?

OTHER TIPS

There is no technical limitation as far as the WebSocket protocol goes, although there are provisions in the spec for rate limiting outstanding connection attempts per IP address to prevent spamming. With just two I doubt you are running into this problem. There may be other policies that your websocket server has that could restrict this further though.

wss://www.mysite.com/sockjs/310/s1a5r_6q/websocket != ws://www.mysite.com/sockjs/310/s1a5r_6q/websocket

This indicates the websocket connection went through a proxy that doesn't understand websocket connections. Most likely, it's a reverse proxy on the server end, offloading the SSL overhead from the server behind the proxy. The proxy provided a secure connection to the client but reported the insecurity of the connection from the server to the client. That's not correct.

It of course is possible, at least if the browser supports the WebSocket API. You don't even need 2 different browsers, you can just open your site in multiple tabs for example in chrome and it should work well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top