Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting "websocket connection invalid" error using socket.io on an ec2 instance?

I have this web app written with express and socket.io using node.js, the app works brillantly on localhost, but when i push to my ec2 server, it connects for like 20 seconds then disconnects, and then connects again etc...

giving me the error on the node console as

warn  - websocket connection invalid
info  - transport end

SERVER

app = express()
server = http.createServer(app)
io = require('socket.io').listen(server)

CLIENT

socket = io.connect()

I know the problem is not with my code, because I fully tested the web app on localhost, so the only problem is where this code is running, which is my ec2 instance?

like image 587
unknown Avatar asked Apr 25 '13 07:04

unknown


3 Answers

There could be many possible reasons you can get this error:

  1. You are using browser that partially or does not support websockets. You can check if your browser supports websockets here.
  2. Using proxy that does not support websocket. If there is some server(load balancer) between your client and your node server that does not support websocket.
  3. You are using socket.io version 0.9.1/0.9.1-1. This behaviour is a reported bug for this version. So upgrade to latest socket.io version which is 0.9.14.
  4. Browser connectivity is firewalled/blocked.
  5. Code related problem.
like image 99
user568109 Avatar answered Sep 20 '22 13:09

user568109


Make sure you're using latest versions of node, express and socket.io on your ec2. Also, provide some data about currently used versions both on your local machine and on ec2 instance.

like image 32
ecdeveloper Avatar answered Sep 18 '22 13:09

ecdeveloper


Running on your local machine you don't have to deal with network latency, NAT issues, or firewalls. Running on EC2 you have all of those.

Web Sockets are relatively new and unstable. So to begin with be sure you're running the latest versions (and let us know what they are). Perhaps the version of socket.io installed on your local machine is different than the version installed in your EC2 server.

like image 34
Old Pro Avatar answered Sep 19 '22 13:09

Old Pro