我有一个测试装置设置,试图在同一个客户端和后端服务器之间创建两个套接字。打开调试后,我可以看到xhr打开两个不同套接字(AAAA和AAAB)的GET请求,并且相应的套接字接收类型为"打开"和数据的sid回显套接字ID(AAAA或AAAB)。我在下面的曲目中突出显示了这些内容。但是,这些都发生在socket.on之前(" connect ...函数被调用,因此socket.io.engine.id仅反映第二个套接字的请求,并且该方法似乎被调用两次。如果我猜测,查找是看到以两个连接使用的/结尾的URI并且正在读取后者(好像它不能区分两个未完成的调用)。我正在维护一个显示的channelName执行io.connect的对象,这样我就可以跟踪回调哪个套接字。
我希望跟踪的这一部分可能会显示发生了什么 - 我还没有找到订阅被管理的地方,以了解它如何查找所有人的监听器...两个io.connect呼叫(一个用于NatA和NatB的一个使用相同的URI和端口,并且都使用forceNew设置为true:
console.log(this.channelName+": Connecting to " + uri);
this.socket = io.connect(uri,{'channelName': initEvent.channelName, 'forceNew': true});
this.socket.on("connect", function() {
console.log(self.channelName+": Setting SocketID:"+self.socket.io.engine.id);
所以,在下面的日志中,你可以看到调用io.connect的NatA和NatB标签,以及调用on(" connect"的地方),但只有第二个NatB套接字是叫它,它被叫两次......
NatA:正在连接http://localhost:3001
socket.io-client:url parse http://localhost:3001 + 0ms
socket.io-client忽略http://localhost:3001 + 0ms
的套接字缓存socket.io-client:manager readyState closed + 0ms
socket.io-client:经理开放http://localhost:3001 + 1ms
engine.io-client:socket创建传输"轮询" + 0毫秒
engine.io-client:轮询轮询+ 1毫秒
engine.io-client:polling-xhr xhr poll + 1ms
engine.io-client:polling-xhr xhr open GET:http://localhost:3001/socket.io/?EIO=3&transport=polling&t=1443463452620-0 + 1ms
engine.io-client:polling-xhr xhr data null + 1ms
engine.io-client:套接字设置传输轮询+ 1ms
socket.io-client:经理连接尝试将在20000 + 6ms后超时
socket.io-client:manager readyState opening + 1ms
NatB:正在连接http://localhost:3001
socket.io-client:url parse http://localhost:3001 + 10ms
socket.io-client忽略http://localhost:3001 + 9ms
的套接字缓存socket.io-client:manager readyState closed + 2ms
socket.io-client:经理开放http://localhost:3001 + 1ms
engine.io-client:socket创建传输"轮询" + 5ms的
engine.io-client:轮询轮询+ 1毫秒
engine.io-client:polling-xhr xhr poll + 1ms
engine.io-client:polling-xhr xhr open GET:http://localhost:3001/socket.io/?EIO=3&transport=polling&t=1443463452629-1 + 1ms
engine.io-client:polling-xhr xhr data null + 0ms
engine.io-client:套接字设置传输轮询+ 1ms
socket.io-client:经理连接尝试将在20000 + 6ms后超时
socket.io-client:manager readyState opening + 0ms
engine.io-client:轮询轮询获取数据ArrayBuffer + 8ms
engine.io-client:socket socket receive:type" open",data" {" sid":" As6yk_kvlPxYGYdBAAAA ""升级":["网页套接字&#34]," pingInterval":25000" pingTimeout":60000}&#34 ; + 4ms的
engine.io-client:socket socket打开+ 1ms
socket.io-client:manager open + 12ms
socket.io-client:套接字传输已打开 - 连接+ 0ms
engine.io-client:套接字启动升级探针+ 1ms
engine.io-client:套接字探测传输" websocket" + 0毫秒
engine.io-client:socket创建传输" websocket" + 0毫秒
engine.io-client:轮询轮询+ 1毫秒
engine.io-client:polling-xhr xhr poll + 0ms
engine.io-client:polling-xhr xhr open GET:http://localhost:3001/socket.io/?EIO=3&transport=polling&t=1443463452647-2&sid= As6yk_kvlPxYGYdBAAAA + 1ms
engine.io-client:polling-xhr xhr data null + 0ms
engine.io-client:轮询轮询获取数据ArrayBuffer + 4ms
engine.io-client:socket socket receive:type" open",data" {" sid":" QRjctK24vsx9-rJzAAAB ""升级":["网页套接字&#34]," pingInterval":25000" pingTimeout":60000}& #34; + 1ms的
engine.io-client:套接字套接字打开+ 0ms
socket.io-client:manager open + 9ms
socket.io-client:套接字传输已打开 - 连接+ 8ms
engine.io-client:套接字启动升级探针+ 1ms
engine.io-client:套接字探测传输" websocket" + 0毫秒
engine.io-client:socket创建传输" websocket" + 1ms的
engine.io-client:轮询轮询+ 0ms
engine.io-client:polling-xhr xhr poll + 0ms
engine.io-client:polling-xhr xhr open GET:http://localhost:3001/socket.io/?EIO=3&transport=polling&t=1443463452655-3&sid= QRjctK24vsx9-rJzAAAB + 1ms
engine.io-client:polling-xhr xhr data null + 0ms
engine.io-client:套接字探测传输" websocket"开了+ 1ms
engine.io-client:套接字探测传输" websocket" pong + 12ms
engine.io-client:套接字暂停当前传输"轮询" + 0毫秒
engine.io-client:轮询我们当前正在轮询 - 等待暂停+ 1ms
engine.io-client:套接字探测传输" websocket"开了+ 0ms
engine.io-client:套接字探测传输" websocket"乒乓+ 3毫米
engine.io-client:套接字暂停当前传输"轮询" + 1ms的
engine.io-client:轮询我们当前正在轮询 - 等待暂停+ 0ms
engine.io-client:轮询轮询获取数据ArrayBuffer + 7ms
engine.io-client:socket socket receive:type" message",data" 0" + 1ms的
socket.io-parser解码0为%j + 0ms对象{类型:0,nsp:" /"}
NatB:设置SocketID:QRjctK24vsx9-rJzAAAB
全球:发布ChannelInitialized:{" channelName":" NatB"}
engine.io-client:轮询预暂停轮询完成+ 3毫秒
engine.io-client:轮询暂停+ 1毫秒
engine.io-client:套接字更改传输和发送升级包+ 0ms
engine.io-client:socket设置传输websocket + 1ms
engine.io-client:套接字清除现有传输轮询+ 0ms
engine.io-client:轮询忽略民意调查 - 运输状态"暂停" + 0毫秒
engine.io-client:轮询轮询获取数据ArrayBuffer + 1ms
engine.io-client:socket socket receive:type" message",data" 0" + 0毫秒
socket.io-parser解码0为%j + 7ms对象{type:0,nsp:" /"}
NatB:设置SocketID:QRjctK24vsx9-rJzAAAB
答案 0 :(得分:1)
我没有在你发布的代码中看到如何打开两个套接字,但如果在同一个JavaScript对象中打开每个套接字并且你将两个套接字映射到this.socket
,那么第一个套接字是第二次被记忆覆盖。