-
Notifications
You must be signed in to change notification settings - Fork 14.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Express 4 with Socket.io #2145
Comments
Hi, Hope that helps.. :) |
No this dosen't work infact it breaks the entire code , express works fine but not socket.io |
what do u mean by breaks all code ? whats the error u get ? |
i find express 4 different from express 3 i get following error Error: listen EADDRINUSE
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1042:14)
at listen (net.js:1064:10)
at Server.listen (net.js:1138:5) |
aaaah.. !! this is a different issue.. this means 3000 port is already used by some other process |
@gs-akhan thanks , you were right infact everything was in place only problem was i created express app using express genrator which create a dir ./bin/www which has following code #!/usr/bin/env node
var debug = require('debug')('demo.app');
var app = require('../app');
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
}); which caused above error adding following lines to end of app.js var server = http.createServer(app);
var io = require('socket.io').listen(server);
server.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
}); Solves it thanks @gs-akhan |
Hi guys, thanks for getting this figured out. In the future, though, this is a type of question that would be better sited for something like stackoverflow.com :) |
FWIW, I was able to solve this by removing boilerplate error handler middleware. Have opened an issue with express-generator. @programming-kid the solution you mentioned did not solve the issue for me |
I am new to Express 4 & socket.io i can't get a working example of express4 with socket.io ,all examples are about express 3 and socket.io
here is my app.js
here is my client code
i can't get it working
/socket.io\socket.io.js return 404 on client side
Can anyone please help me get setup with socket.io with Express4.2
thanks
The text was updated successfully, but these errors were encountered: