Zuzuesque
Zuzuesque

Reputation: 105

Migrating from socket.io 0.9.x to 1.4.x - can't get socket.io to start

I am in the process of updating an old application to use socket.io 1.4 instead of 0.9 (and express 4 instead of 3) but I am unable to get socket.io to start up. In my old app I would set up things as follows:

var socket = require('socket.io');
var express = require('express');
var http = require('http');

var app = express();
var server = http.createServer(app);

var io = socket.listen(server);
server.listen(8080);

According to the 1.x docs I thought this should work:

var express = require('express');
var http = require('http');

var app = express();
var server = http.createServer(app);

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

I can't figure out what I am missing. Tried to add io.listen(server) as well in case passing the server wasn't enough, but that has no effect either. I don't think it is the syntax which is wrong... but I am obviously missing some step to get this working as before.

Upvotes: 0

Views: 364

Answers (1)

jfriend00
jfriend00

Reputation: 707238

I'll try to supply a useful answer here so you can close up the question.

Your second block of code is completely consistent with this combination shown in the socket.io doc. The only difference is that they use the .Server() constructor and you use the .createServer() method which (if you look at the code) do the same thing:

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
server.listen(8080);

So, I don't think this is where the issue is. Some things to check:

  1. Are there any startup errors showing in the node console?
  2. How do you know that socket.io is not started? One difference in the post 1.0 world is that the socket.io server code does not output anything to the console when it starts like it did on the 0.9x world. This has confused many.
  3. If you still have issues, please show the corresponding client code.

Edit: As the OP discovered in comments when investigating some other things I asked, the socket.io server was starting just fine - the OP was just expecting to see some console output that used to be there before the 1.x version.

Upvotes: 1

Related Questions