Currently my application based on Expressjs + angularjs. I want to start few 2 way calls along with existing http calls. I went through few websocket chat tutorials but nonew of them integrated with expressjs.
Do I start websocket connection on new port? How do I integrate my angularjs with websocket?
Can I just create few more routes and controller functions and have some of them work 2 way?
Nothing special is needed, you can use the same port for Socket.IO and express.
e.g. in my project I do something like this:
var express = require('express');
var io = require('socket.io');
var app = express();
var server = http.createServer(app).listen(SERVER_PORT, function() {
console.log('Express server listening on port ' + SERVER_PORT);
});
// let socket.IO listen on the server
io = io.listen(server);
io.on('connection', function(socket) { /* handle connection */ });
AFAIK there is also an example with express on the Socket.IO wiki.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With