socket.io: Bad Request, connecting from outside - node.js

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

Related

Chrome cannot connect to http://localhost:8080 but http://127.0.0.1:8080 works

This question is similar to the one here, but that question is 18 months old and I have more specific information.
I am running a node.js development server on my local PC (Windows 7), and it is set to listen on localhost:8080.
Using IE11 or Firefox, I can successfully connect to both http://localhost:8080 and http://127.0.0.1:8080
Using Chrome (version 58), I can successfully connect to http://127.0.0.1:8080, but I can't connect to http://localhost:8080 - it gives me ERR_CONNECTION_RESET.
However, if I configure the node server to a different port, say 8081 or 8888, then Chrome can happily connect using localhost as well. So it is not a name resolution problem, but specific to choice of port number.
So what is special in Chrome about localhost when using port 8080?
Maybe this is an IPv4 / IPv6 issue. If your server only listens on IPv4 and you connect to localhost, it could be that it uses the IPv6 address and gets the connection refused.
You could try to start the server on IPv4 and IPv6 to resolve this.
I had a similar issue and found the answer here. I was able to successfully start my project on http://127.0.0.1, but not on any specific port. I had no issues before and all of a sudden I couldn't connect my project on any localhost port, but I had no problem if I used Safari or Firefox. Try running your project in incognito and if it works then you have session running from a project you were testing. Hope it answers your problem if you haven't already.
I had a similar problem, I tried a bunch of things but the only thing that ended up working was resetting Chrome settings. Hope it helps.

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.

Socket.IO Connection Not working on University Wifi

I have created an chat app using Socket.IO . It works fine on my home internet. But whenever I am at my university and connected to versity wifi internet, I can't get connected at all. Its facing 'net::ERR_CONNECTION_TIMED_OUT' error.
Here is the url: demo.codesamplez.com/ultrachat/demo.html (You will may get it OK, as I do on home)
I guess, this might be some kind of firewall issue or something?
Does anybody has any clue how to go forward for solving this? Thanks in advance.
Switching from HTTP to HTTPS should get around the problem with incompatible proxy server. That forces the proxy to use HTTP tunneling to maintain the connection instead performing whatever magic it does.

Node.js and Socket.IO Not Responding in Some Servers

I have simple Node.js and Socket.IO app running on Nodejitsu. The App is running perfectly from home and some other Internet services but not working from my work!
Here is the error Message which I am getting
The connection to ws://behseini-socketproject.jit.su/socket.io/1/websocket/QtVm6E79WwGLwBVjN7el was interrupted while the page was loading.
this.websocket = new Socket(this.prepareUrl() + query);
socket.io.js (line 2371)
GET http://behseini-socketproject.jit.su/socket.io/1/?t=1370531712581 200 OK
535ms
socket.io.js (line 1659)
ParamsHeadersResponse
fPtjDNnugmPPXKbnN7ep:60:60:websocket,htmlfile,xhr-polling,jsonp-polling
Can you please let me know why this is happening? is this kind of Firewall issue?
Thanks
After talking with you on the #nodejitsu IRC channel, it seems that this may indeed be a problem with your work proxy/firewall.
As was suggested to you in the chat last night, you could always try to use secure websocket connections (wss rather than ws) to see if that will allow your connections to pass through.
If that doesn't work, you would need to send your connection outside of your work's connection. For instance, proxying into a computer at your home and using your home network while you're at work and want to use websockets.

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.

Resources