需要帮助将socket.IO 0.9迁移到1.0。 以下1.0代码运行没有错误,但是当我的iOS客户端尝试按照惯例连接到服务器时,它完全静音。只要尝试与服务器建立套接字连接,iOS客户端就会收到错误状态400。
// Socket.IO 0.9实现
var express = require('express');
var bodyParser = require('body-parser');
var server = express(); // better instead
server.use(bodyParser.json());
server.use(bodyParser.urlencoded());
var io = require ('socket.io').listen(server.listen(port));
io.configure(function () {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
io.set("close timeout", 10);
io.set('authorization', function (handshakeData, callback) {
// process handshake
});
io.set('log level', 1); // reduce logging
});
io.sockets.on('connection', function(socket) {
...
});
// Socket.IO 1.0实现
var express = require('express');
var bodyParser = require('body-parser');
var server = express(); // better instead
server.use(bodyParser.json());
server.use(bodyParser.urlencoded());
var io = require ('socket.io')(server.listen(port));
io.use(function(socket, next){
// never triggered!
next();
});
io.on('connection', function (socket) {
// never triggered!
});