admin管理员组文章数量:1425814
I'm initiating a socket connection using Socket.IO to a Node.js server and it's as simple as follows:
var socket = io.connect(url, options);
At some point, I need to disconnect this socket when it's no longer need and reconnect it. I'm having some issues initiating a pletely new socket and I thought it would be much better to simply reconnect the same socket rather then rebuilding another socket and adding listeners to it.
Based on the socket.io documentation, I should be able to manually reconnect a socket by calling:
socket.connect();
But when I call that method, I'm getting an error in the console: Uncaught TypeError: Object # has no method 'connect'
Am I missing anything?
I'm initiating a socket connection using Socket.IO to a Node.js server and it's as simple as follows:
var socket = io.connect(url, options);
At some point, I need to disconnect this socket when it's no longer need and reconnect it. I'm having some issues initiating a pletely new socket and I thought it would be much better to simply reconnect the same socket rather then rebuilding another socket and adding listeners to it.
Based on the socket.io documentation, I should be able to manually reconnect a socket by calling:
socket.connect();
But when I call that method, I'm getting an error in the console: Uncaught TypeError: Object # has no method 'connect'
Am I missing anything?
Share Improve this question asked May 21, 2012 at 21:05 ElieElie 7,4238 gold badges33 silver badges35 bronze badges 2- You need to provide more code. It seems a problem of scope. – Alexander Commented May 21, 2012 at 21:09
- 2 Alexander, it's not a scope issue. The connect socket function is simply not supported as stated in the documentation. – Elie Commented May 21, 2012 at 22:06
1 Answer
Reset to default 7You should call the socket in your socket
object :
var socket = io.connect(url, options);
socket.socket.connect();
See this question it is related : Socket IO reconnect?
本文标签: javascriptDisconnecting and manually reconnecting SocketIOStack Overflow
版权声明:本文标题:javascript - Disconnecting and manually reconnecting Socket.IO - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745447380a2658725.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论