13

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!

Aidoru
  • 555
  • 1
  • 5
  • 16

1 Answers1

16

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.

robertklep
  • 198,204
  • 35
  • 394
  • 381
  • 3
    It appears they are the same, although I came across a strange issue with my server where `io()` would connect to the socket service, whereas `io.connect()` would not. I cannot explain why. This is through nginx using port forwarding websockets – Felipe Dec 12 '17 at 17:24