Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

Thank you!

like image 910
Aidoru Avatar asked Aug 05 '17 11:08

Aidoru


People also ask

What is the difference between Socket.IO and socket IO client?

socket-io. client is the code for the client-side implementation of socket.io. That code may be used either by a browser client or by a server process that is initiating a socket.io connection to some other server (thus playing the client-side role in a socket.io connection).

Is WebSocket and Socket.IO different?

First of all, every modern browser supports WebSockets these days. Socket.IO uses much more boilerplate code and resources to make it fall back to other technologies. Most of the time, you don't need this level of support. Even in terms of network traffic, Socket.IO is way more expensive.

What is the difference between Socket and WebSocket?

WebSocket is a protocol, Socket is an endpoint - got it thanks. Also, a simple google search returned "The current API specification allowing web applications to use this protocol(WebSocket) is known as WebSockets" (note the plural).

What is Socket.IO connection?

Socket.IO is a library that enables low-latency, bidirectional and event-based communication between a client and a server. It is built on top of the WebSocket protocol and provides additional guarantees like fallback to HTTP long-polling or automatic reconnection.


1 Answers

There is no difference.

If you look at the source code for the SocketIO client, io is declared as follows:

module.exports = exports = lookup;

And io.connect() is declared in the same way:

exports.connect = lookup;

They both refer to the same (internal) function lookup.

I think that io.connect exists to make the client backward compatible with older versions of SocketIO.

like image 106
robertklep Avatar answered Sep 21 '22 02:09

robertklep