Browser, behind Squid, can't establish connection to socket.io websockets transport - node.js

My problem is simple to explain but not so simple to fix I think since I haven't found a solution yet.
I'm developing an API. The backend is developed using NodeJs and Socket.Io. Everything works perfect but the issue arises when I'm on a net that's behind a firewall, Squid in this case. It is the browser who is behind the firewall not the server (NodeJs).
The thing is that I get this error:
WebSocket connection to 'ws://mydomain.com/socket.io/1/websocket/vN8hWt_EjV0Z5P5-GwrW' failed: Unexpected response code: 502 (socket.io.js:2)
and I don't know how to the browser can skip Squid.

Related

Google App Engine - socket.io throws errors before successfully connect

Ok so... For a while web sockets have been implemented in the GAE flex environment.
I've got an app deployed there and everything works "sorta" fine except that sometimes
When Connecting or
After a random disconnect and it tries to reconnect
I get a couple of these errors:
POST https://XXX.appspot.com/socket.io/?EIO=3&transport=polling&t=N00Ml-1&sid=XuKv8-6R2TZrIERGAAAO 400
WebSocket connection to 'wss://XXX.appspot.com/socket.io/?EIO=3&transport=websocket&sid=XuKv8-6R2TZrIERGAAAO' failed: WebSocket is closed before the connection is established
GET https://XXX.appspot.com/socket.io/?EIO=3&transport=polling&t=N00Ml-2&sid=XuKv8-6R2TZrIERGAAAO 400
I've googled a lot and tried a lot of the stuff suggested to people that had similar issues (most of them BEFORE GAE introduced websocket support).
After a couple of these errors it just connects and everything is fine... I've tried forcing transport as websocket on the client side but it doesn't seem to change anything.
Is there any fix? Should i just change cloud provider?
Not posting any code since it's the basic socket.io nodejs implementation, in fact I've tested with an empty basic implementation and it's the same thing, my best guess is they havn't implemented the load balancer correctly? Anybody has these issues? Should i go aws instead?
I managed to fix this... I've posted on the socket.io github issues
https://github.com/socketio/socket.io/issues/3543
And here's a link to a better explanation
https://github.com/socketio/socket.io/issues/3612#issuecomment-656667871

socket.io client can't upgrade from XHR long polling to websocket

We have a server which do implement socket.io in NodeJS on Heroku.
We have a bunch of clients (Raspberry pi's) destributed on different networks across our country. They do implement socket.io clients in a NodeJS application.
It do work very well on 17/18 devices. We do have one device which are not able to upgrade the socket.io connection from a long-polling type to an actual websocket.
I cannot find the reason why.
Our server is setup with the following options:
Server settings
This is what the logs on our heroku server tells about the connection with the problematic client:
Heroku logs
As all clients are setup exactly the same way, i do not actually suspect any problems on the raspberries themselves.
Could it be a network problem where this one client is located?
- Behind the router, blocking some port etc?
Hope you have some suggestions to what the problem could be.
You tell if you need anymore information.

websocket server using nodejs+socket.io cannot be connected by tester sites while ws can

I want to create a websocket server. I heard that socket.io is a good choice.
I tried socket.io with nodejs(v4.4.7) (npm install --save socket.io), using its sample server side code. A little confused why the client side code is using "http://" rather than "ws://" protocol, but after I setup a real server for testing, I found both "http//" and "ws//" will work using the official code.
Everything is fine till now. But soon I found I can't establish a connection using third-party online tester sites like:
1. www.websocket.org/echo.html
2. www.blue-zero.com/WebSocket
The connection seemed never established or closed asap connected,
I found "Firefox can't establish a connection to the server at ws://mytestserver:8888/?encoding=text" in Firefox console,
or "WebSocket connection to 'ws://mytestserver:8888' failed: Connection closed before receiving a handshake response" in Chrome console.
At last I changed socket.io to ws (npm install --save ws). using sample code from github.com/websockets/ws. all tester sites worked well.
(Of course, my final purpose is not to make a tester site work. the fact is the websocket lib based on nopoll integrated in my chip has exactly the same behavior as the tester sites.)
Anybody knows the reason why socket.io does not work with 3rd-party clients while ws does? Thanks a lot.
socket.io requires a socket.io server on the server-side end of things. It will not connect to only a webSocket server.
While socket.io uses webSocket as the underlying transport, it adds a layer on top of webSocket to implement a whole bunch of additional features and that requires server-side support for socket.io. So, you can't connect to a plain webSocket server with the socket.io client.
You must match:
webSocket client <==> webSocket server
socket.io client <==> socket.io server

Why does my WebSockets handshake fail with ERR_CONNECTION_RESET?

I've just created a new sails.js app with
sails new testProject
Then I did
sails lift
Now I navigate to my address (http://153.92.xx.xxx:1337) and everything works.
However, I know that sails uses XHR by default but tries to upgrade to WebSockets if it can. No matter what I try I can't get WebSockets to work.
I can see that the app tries to connect but is just (pending) for about 18 seconds before it gives up. It then goes back to XHR.
The error reads:
WebSocket connection to 'ws://153.92.xx.xxx:1337/socket.io/?__sails_io_sdk_version=0.11.0&__sails_io_sdk_platform=browser&__sails_io_sdk_language=javascript&EIO=3&transport=websocket&sid=8qjNepcGV5Rh3VvzAAAA' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
What could I be doing wrong?
Sailsjs v0.11.2
Nodejs v0.12.7
Debian 8 x64
iptables has full ACCEPT on everything
I believe this is because of a personal firewall.
Changing the port from 1337 to 80 made everything work.
Accessing the site from a different machine worked ok.
My best guess is that a personal firewall that was on my machine blocks websockets if they are not using "standard" ports.

Meteor: Error during WebSocket handshake: Unexpected response code: 400

What could be the possible cause of the error Error during WebSocket handshake: Unexpected response code: 400?
The app is hosted on ubuntu and deployed using the npm mup package. I included my bundled ssl pem file within mup.json.
Is there anything else that I need to configure on the server?
This can be caused by one of the three reasons:
Some ISPs may use proxies which don't support websockets. This is more apparent over 3G networks
If your app has crashed. Meteor tries to connect to the server and can't since it's not online.
This can also happen if Nginx isn't configured to use WebSockets, and your MUP instance is sitting behind a WebSocket.
So if your app is working as expected (maybe just takes a bit too long to get connected) & has this error in development console it's likely due to a proxy server. To avoid this try getting SSL (https://) installed on your server too. This way the ISP or proxy is not able to alter your app's connection.
I had this error when I was connecting via a hotel WiFi. The problem was that you are always connecting to the internet via their proxy.
My solution to this was to use my mobile phone as a Wifi hotspot. I have Android 6.0.1, and you can access the menu through:
Settings > More > Tethering & portable hotspot > Set up Wi-Fi hotspot (and then enable 'Portable Wi-Fi hotspot')

Resources