Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have been having issues for a few days trying to set up a simple websocket server on an Amazon EC2 instance. I am using a micro instance of Linux. After booting up for the first time, I updated all OS packages, followed this great guide for getting node and npm installed, installed socket.io, express (not currently using), and websocket.io which includes the websocket-server by miksago.

First, my attempts with Socket.io as the backend. I set up a simple server using the sample code from their website, listed below. I run this with sudo node server.js. I use sudo so that I can listen on port 80, errors result otherwise. From here, I put my amazon public DNS into the location field at the websocket.org echo test. When I press connect, my server will output debug - destroying non-socket.io upgrade. I have a console output within the "connection" listener that never gets printed, so it seems that there is an error before the connection request gets through. It may be that I have to use socket.io client side for a socket.io server to work, but I could not find any definitive answer on that.

My second attempt was using websocket-server by Miksago. I'll list the source for the server below as well. This time, I was able to see that console output on the connection request, but a connection was still not established. I tried printing the connection.header object but received an error.

I'm trying to set up a simple server just to get the basics going and I haven't been able to pin down what the issue is. I'm using websocket.org to test the server since their client is set up correctly. What am I doing wrong setting up the server?

Socket.io server
var io = require('socket.io').listen(80);

io.sockets.on('connection', function (socket) {
  console.log("Connection request on socket.io server");
});



Websocket-Server
var ws = require("websocket-server");

var server = ws.createServer();

server.addListener("connection", function(connection){
  console.log("Connection request on Websocket-Server");
});

server.listen(80);

Edit: Debug output from node-websocket-server. This is a snippet of the output from console.log(connection._req); The information looks right, but the server is simply not establishing the connection.

httpVersion: '1.1',
complete: true,
headers: 
 { upgrade: 'websocket',
   connection: 'Upgrade',
   host: 'ec2-50-16-107-223.compute-1.amazonaws.com',
   origin: 'http://websocket.org',
   'sec-websocket-key': 'HdgJaiL2TZ4iyOHTarmlig==',
   'sec-websocket-version': '13' },
trailers: {},
readable: true,
url: '/',
method: 'GET',
statusCode: null,

Edit2: Use websocket.io as a websocket server on Node.js. It works without needing client side js files, and is more up to date with spec. It is available through npm and git.

share|improve this question
    
Did you try the exact example code provided on the socket.io site? –  ceejayoz Jan 3 '12 at 16:31
    
Yes, same debug error is printed. –  brodney Jan 3 '12 at 16:47
    
For the client-side too? –  ceejayoz Jan 3 '12 at 16:50
    
It appears that node-websocket-server may just be buggy. It hasn't been updated in a few months. A suggestion on the git page there pointed me to websocket.io, the websocket server that socket.io is built on. I tried the sample code there and it worked with the websocket.org echo test. –  brodney Jan 4 '12 at 1:02

1 Answer 1

up vote 0 down vote accepted

According to this StackOverflow question, you must use socket.io's client-side code. Using websocket.org's client-side code is going to give you this error.

share|improve this answer
    
That seems to be the case for the socket.io server. Do you have any idea why the miksago websocket server is also not establishing websocket connections? I'm updating the main question with some more debug output from that server. –  brodney Jan 3 '12 at 21:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.