最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Express.js with websockets - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question edited Jul 18, 2014 at 7:18 raju asked Jun 28, 2014 at 10:19 rajuraju 5,00817 gold badges67 silver badges121 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

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.

发布评论

评论列表(0)

  1. 暂无评论