简体   繁体   English

使用socket.io在io()和io.connect()之间的差异

[英]Differences between io() and io.connect() using socket.io

I would like to know what are the differences between 我想知道它们之间有什么区别

var socket = io();

and

var socket = io.connect();

using socket.io in my script (client side) 在我的脚本中使用socket.io(客户端)

Thank you! 谢谢!

There is no difference. 没有区别。

If you look at the source code for the SocketIO client, io is declared as follows : 如果查看SocketIO客户端的源代码, io声明如下

module.exports = exports = lookup;

And io.connect() is declared in the same way : io.connect() 以相同的方式声明:

exports.connect = lookup;

They both refer to the same (internal) function lookup . 它们都引用相同的(内部)函数lookup

I think that io.connect exists to make the client backward compatible with older versions of SocketIO. 我认为io.connect存在使客户端向后兼容旧版本的SocketIO。

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

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