#服务端代码 var app=require(‘express’)(); var http=require(‘http’); var server=http.Server(app); var io =require(‘socket.io’)(server);
var allSockets={};
io.on(“connection",function (socket) { var deviceNo=socket.handshake.query.deviceNo; socket.username=deviceNo; console.log(deviceNo +” device connected");
socket.on("disconnect",function () {
delete allSockets[socket.username];
console.log(socket.username+" device disconnected");
});
socket.on("control",function (msg) {
// body...
var data =JSON.parse(msg)
var key=data.key;
var selectSocket=allSockets[key];
if(selectSocket){
selectSocket.emit("message",data.msg);
}
else{
console.log("control failure,socket is null");
}
});
})
server.listen(8088,function () { // body… console.log(“listening on 8088”); })
#客户端代码 var socket = IO.Socket("http://localhost:8088/", new Quobject.SocketIoClientDotNet.Client.IO.Options { QueryString = “deviceNo=bar” + vak });
#Client自动断开 在用Socket.io client循环创建Socket建立连接,在测试的时候,发现连接数到100左右就会自动断开,大神帮忙看下是哪里出了问题