Why does my WebSockets handshake fail with ERR_CONNECTION_RESET? - node.js

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.

Related

Cannot establish connection using port number explicitly

I am new to servers and networking so pardon my ignorance.
I have a Heroku application running a NodeJS server. I am using console.log() to output the port its using to the console. But when i use the port to try to perform a GET request from my browser it keep loading forever. My request is something this:
https://example.herokuapp.com:28222/getHighest
When i remove the port number, it works perfectly:
https://example.herokuapp.com/getHighest
I am ultimately trying to perform GET and POST request from a C application. The HTTP library i am using seemingly requires a port for a connection. I am using this library: GitHub. It works perfectly when i run it locally with localhost:8080/getHighest but not when i use my heroku app.
As suggested by #tadman using the default https port 443 solved the issue.

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')

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

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.

socket.io websocket connection invalid (latest chrome)

After installing node.js, I followed this tutorial to start a simple chat server. It was very easy to setup and is working, but I have noticed two problems:
1.) I am getting this warning from socket.io
info - socket.io started
debug - served static /socket.io.js
debug - client authorized
info - handshake authorized 1385647068766475337
debug - setting request GET /socket.io/1/websocket/1385647068766475337
debug - set heartbeat interval for client 1385647068766475337
warn - websocket connection invalid
This doesn't make sense to me because I didn't touch anything with socket.io and I am using the latest chrome version (23) which I know supports websockets (I am able to successfully connect to them with PHP-Websockets). It continues to use XHR instead, but I am really interested in getting the Websocket functionality working.
2.) When I go to localhost:8080 to connect to the chat server, it takes around 7-8 seconds for it to prompt me for my name and actually connect me to the server. I have a feeling this may be because it is reverting to XHR, but I don't really know much about it so I can't say. Any thoughts?
I saw this behaviour when using an older version of socket.io with later chrome builds (and other browsers also). It would timeout then fallback to xhr polling. To check your version of the socket.io library you are using, at your shell (linux/unix) type:
npm ls| grep socket.io
And it should tell you the version. The latest at this time is 0.9.13, which works.
If you are running the tutorial from http://psitsmike.com note that the package.json file hardcodes an older version of socket.io which doesn't work with the latest browsers.
Hope this helps.
I too was facing similar issues.
Your case -
Try deleting your cookies, sometimes the xhr-polling option once connected successfully is saved to cookies and reused every next time. Similar question answered here
Also debug - served static /socket.io.js sometimes come when the socket.io file is referred incorrectly inside the html or jade template file. Try correcting the script src link in case it wrong. It should be something like - var socket = io.connect('http://localhost:3000'); OR you can also try removing the link all together like this - var socket = io.connect();
Hope it helps.
I had the exact same issue. this might be old. but My setup is on digitalocean. what happens is that usually people who run node apps on one server use nginx for the port listen and node under its own dedicated port. nginx did not forward the websocket port to the node, only port 80 which nodejs was not initialised to begin with.
http://nginx.org/en/docs/http/websocket.html
You need to make sure your nginx is configured properly for this.
I just added the port to the io.connect directly connecting to the node server and avoiding nginx.

socket.io: Bad Request, connecting from outside

I installed node.js and the module socket.io (http://socket.io).
The chat example of socket.io works just fine for me, typing in my
browser
http://localhost:3000
But I cannot get anything to work using another IP, eventhough the
server listens on all interfaces (i.e. 0.0.0.0). My ethernet
interface has the address 192.168.1.1, typing in my browser
http://192.168.1.1:3000
I get the chat webpage, but my Firebug (still on the same computer)
says:
NetworkError: 400 Bad Request
and the websocket connection is not established. The result is, that I
cannot reach my websockets from the outside, whatever code I write.
I use node v0.6.12, firefox 11.0, Ubuntu 11.10.
Questions:
1) Can anybody confirm this error?
2) How can I reach a websocket from another computer than localhost?
3) Is there any socket.io example where the connection works from the outside on a normal ubuntu installation?
Thanks!
Solved: disable proxy in Firefox
Apparently my Ubuntu installation started ziproxy automatically
and configuered Firefox to use it. Setting Firefox to "no proxy"
solved the problem. Now I can connect to my websockets from the
outside.
Share your code.
are you using express??
use --> app.listen(3000);

Resources