Migration from 0.9 socket.io

Socket.io documentation:

Starting the server

Previously:

var io = require('socket.io'); var socket = io.listen(80, { /* options */ });

Now:

var io = require('socket.io'); var socket = io({ /* options */ });

Then how can I select server port now ?

Also is it possible to use socket.io without http server (express, node http server and etc.) ?


你可以在不使用Express / http的情况下使用它,只需将一个端口传递给参数即可。

var port = 3000;
var io = require('socket.io')(port);

io.on('connection', function(socket) {
    console.log('a user connected');
});
链接地址: http://www.djcxy.com/p/63182.html

上一篇: Socket.IO简单示例不起作用

下一篇: 从0.9 socket.io迁移