So I'm trying to use the sample heroku application: https://github.com/lstoll/socket-io-chat-heroku as a template to build my own socket.io application, but I'm running on Express 4.0, Node 0.10.x, and Socket.io 0.9.16.
Now the problem is that when I run my server, everything is fine, but when I run my client, I get the following error:
Uncaught ReferenceError: require is not defined socket.io.js:12
Uncaught ReferenceError: io is not defined chat2:2
My relevant server code is as follows:
var app = express();
var http = require('http');
var server = http.createServer(app);
var sio = require('socket.io');
var port = 3000 || process.env.PORT;
server.listen(port);
var io = sio.listen(server);
io.sockets.on('connection'), function(socket) {
...
});
On my client side, I have the following: I've tried both (this is in jade, by the way):
script(src='/socket.io/socket.io.js') OR script(src='http://localhost:3000/socket.io/socket.io.js')
var socket = io.connect() OR var socket = io.connect('http://localhost:3000')
Neither of these options have worked, always resulting in an error on the client side. Is there something special to do for Express 4.0? I've asked a very similar question here: Node.js /socket.io/socket.io.js not found express 4.0 but this is another attempt at getting chat to work with a different template.
Update and Edit: after some work, I was able to deploy a heroku app using express 4.0 and socket.io, at: http://salty-escarpment-7398.herokuapp.com/chat.
The problem now is to integrate it back into my current app, and after much work, I now am getting an error:
22:19:56 web.1 | GET /socket.io/?EIO=2&transport=polling 404 26ms - 1.67kb
22:19:59 web.1 | GET /socket.io/?EIO=2&transport=polling 404 25ms - 1.67kb
I have:
io.set('transports', ['xhr-polling']);
io.set('polling duration', 10);
To set it to xhr-polling, and my server code is pretty much identical to what was above. The page loads, though, and it's only when trying to send a chat that nothing happens and the 404 starts appearing.
Thanks