2012-02-28 110 views
3

我有一個socket.io的問題。Node.js和socket.io - 客戶端不握手客戶端應重新連接

此錯誤:警告 - 客戶端不handshaken客戶端應該重新

在控制檯我有錯誤的列表:

debug - setting poll timeout 
    debug - clearing poll timeout 
    debug - xhr-polling writing 7:::1+0 
    debug - set close timeout for client 17348980511779302969 
    warn - client not handshaken client should reconnect 
    info - transport end 

我有這個簡單的應用程序:

require.paths.unshift(__dirname + '/../../lib/'); 

var express = require('express'); 
var app = express.createServer(); 
var io = require('socket.io').listen(app); 
var stylus = require('stylus'); 
var mysql = require('mysql'); 

app.use(express.bodyParser()); 
app.use(express.cookieParser()); 

app.use(stylus.middleware({ src: __dirname + '/public', compile: compile })) 
app.use(express.static(__dirname + '/public')); 
app.set('views', __dirname); 

app.set("view options", { layout: false }); 

app.register('.html', { 
    compile: function (str, options) { 
     return function (locals) { 
      return str; 
     }; 
    } 
}); 

function compile(str, path) { 
    return stylus(str) 
     .set('filename', path) 
     .use(nib()); 
}; 

app.get('/', function (req, res) { 
res.render('index.html', { layout: false }); 
}); 


io.configure(function() { 
    io.set('transports', ['websocket','flashsocket','xhr-polling']); 
    io.set('polling duration', '10'); 
}); 

io.sockets.on('connection', function (socket) { 

    console.log("Connect with ID: " + socket.id); 

    socket.emit("sendid", {id: socket.id}); 

    socket.on('disconnect', function() { 
     console.log("Disconnect with ID: " + socket.id); 
    }); 

}); 

app.listen(3000); 

客戶編號:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html> 
<head> 
    <title>Socket.IO - test</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <script src="/socket.io/socket.io.js" type="text/javascript"></script> 
    <script type="text/javascript"> 

     var WEB_SOCKET_SWF_LOCATION = './WebSocketMain.swf'; 

    var socket = io.connect(null, { 
      'connect timeout': 500, 
      'reconnect': true, 
      'reconnection delay': 500, 
      'reopen delay': 500, 
      'max reconnection attempts': 10 
     }); 

    socket.on('sendid', function (data) { 
      alert("Your socket ID is: " + data.id); 
     }); 

    </script> 
</head> 
<body> 
Test socket.io. 
</body> 
</html> 

回答

4

我已下載最新版本的socket.iosocket.io-client

我設置了連接到socket.io的URL和端口 - 在客戶端。

var socket = io.connect('http://domain.com:port', { 
      'connect timeout': 500, 
      'reconnect': true, 
      'reconnection delay': 500, 
      'reopen delay': 500, 
      'max reconnection attempts': 10 
     }); 
+3

我的socket.io 0.9.9,這不會停止失敗。當我重新啓動應用程序時,我得到了很多這樣的錯誤(10k用戶) – nax 2012-08-06 12:03:46

+0

@jenan:即使在你按照你的建議更新代碼之後,它仍然會給出同樣的錯誤。任何解決方法? – Pritam 2015-04-11 12:56:27