1

I deployed my app to no.de. First issue I had with socket.io was that I had to change the port it was listening to.

  io = require('socket.io').listen(3000),

After changing the port now the script required socket.io.js is nowhere to be found

 script(src="/socket.io/socket.io.js")

I tried and absolute path giving in the port as well but that didn't work. On localhost it worked just fine so I'm really confused on how to fix this.

 GET http://twtups.no.de/socket.io/socket.io.js 404 (Not Found)
 Uncaught ReferenceError: io is not defined

A second look at my logs reveals this // this is from express i think, dunno if related

 Warning: connection.session() MemoryStore is not
 designed for a production environment, as it will leak
 memory, and obviously only work within a single process.
[ Jan 11 11:10:09 Method "start" exited with status 0. ]

UPDATE, Works like this

var app = express.createServer();
var io = require('socket.io').listen(app);
app.listen(80);
3
  • 1
    Show the whole code, probably your Express app is running on port 80 and Socket.IO is served on port 3000, that's your issue (I think). Try to include the SIO file by specifying the whole path. Commented Jan 11, 2012 at 12:35
  • Yes, i am using 80/3000, if i try and to serve them on the same port it gives and error :/ Commented Jan 12, 2012 at 7:53
  • My bad now it works, I should have .listen(app) but I still get that annoying lag I told you about.I think I'll go on github and ask them. Thanks Commented Jan 12, 2012 at 8:04

2 Answers 2

1

What Express version are you using?

The API has changed from Express 2.x to 3.x, so the answer is in the Socket.IO compatibility section at the Migrating from 2.x to 3.x wiki:

Socket.IO's .listen() method takes an http.Server instance as an argument.
As of 3.x, the return value of express() is not an http.Server instance. To get Socket.IO working with Express 3.x, make sure you manually create and pass your http.Server instance to Socket.IO's .listen() method:

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

server.listen(3000);
Sign up to request clarification or add additional context in comments.

Comments

0

I'm not sure what happened (it should work), but you can always try putting socket.io.js somewhere on your main site.

Actually the change of port only matters for WebSocket server. The /socket.io/socket.io.js url is automatically added to your app when you import socket.io, so the file is still served on your main site. What you are saying seems to be very strange and maybe related to no.de. I'm not sure though.

2 Comments

I changed the link so it now points to cdn.socket.io/stable/socket.io.js but i get a new error Uncaught TypeError: Object #<Object> has no method 'connect' . I should mention that i checked the logs and socket.io starts properly
@andrei that's a pretty old version on the CDN, current is 0.8.7

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.