简体   繁体   English

多个socket.io客户端连接无法正常工作(谷歌浏览器,Firefox)

[英]Multiple socket.io client connections not working (Google Chrome, Firefox)

I have a web page containing Javascript code using socket.io to connect to two NodeJS servers (also running the same version of socket.io). 我有一个包含Javascript代码的网页,使用socket.io连接到两个NodeJS服务器(也运行相同版本的socket.io)。 The servers are on the same IP, but different ports. 服务器位于相同的IP上,但端口不同。 The first connection works fine, but the second connection does not seem to work (the on("connect") callback never gets called). 第一个连接工作正常,但第二个连接似乎不起作用(on((“连接”)回调永远不会被调用)。 Any idea why this might be the case? 知道为什么会这样吗?

I am using Google Chrome 21.0.1180.79 and Firefox 14.01. 我使用的是Google Chrome 21.0.1180.79和Firefox 14.01。 The code for connecting to the server is similar to: 连接服务器的代码类似于:

socket = io.connect("http://server", {port:some_port_number});
socket.on("connect", function() {
                       // process connection.
                     });

Thanks 谢谢

There's no option 'port', you should append it to url (http://server:port). 没有选项'port',你应该将它附加到url(http:// server:port)。 Because socket.io ignores 'port' option so it doesn't connect to the same url again (default). 因为socket.io忽略'port'选项,所以它不再连接到同一个url(默认)。 https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM