Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what port does the socketIO client listen to by default?

When you do not specify a port in the io.connect() function on the client side, what port does the client listen to?

eg:

var socket = io.connect('http://example.com/'); // listening to port 80?

The reason I ask is because I deployed the server side of this application on heroku. The front end is an IOS application. The objective C socketIO library I'm using for the front end (https://github.com/pkyeck/socket.IO-objc) requires me to specify a port. But I'm not sure what port I should listen to since this is not static on the server side.

I wrote client program in javascript for testing and it works when I do not specify a port.

Any help would be much appreciated.

like image 803
SivaDotRender Avatar asked Sep 11 '14 03:09

SivaDotRender


People also ask

Which port does Socket.IO use?

We make the http server listen on port 3000.

What protocol does Socket.IO use?

Socket.IO primarily uses the WebSocket protocol with polling as a fallback option, while providing the same interface.

Does Socket.IO use HTTP?

js) and the Socket.IO client (browser, Node. js, or another programming language) is established with a WebSocket connection whenever possible, and will use HTTP long-polling as fallback.

What is Socketio client?

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.


Video Answer


1 Answers

It listens on the port the server listens to. Imagine you set your server to listen port 8080. Then you load your page at http://localhost:8080 and the server returns the page which contains the socket related JS code.

  1. If you don't specify any port or host as in var socket = io.connect();, it defaults to the host and port of the current page.
  2. If you specify only the host which is same as the current host, it defaults to the port of the current host.
  3. If you specify only the host which is different from the current host, it defaults to port 80 if the protocol is HTTP. If the protocol is HTTPS, then the port defaults to 443.

Here is the related code for url.js parser.

like image 76
Eye Avatar answered Sep 19 '22 08:09

Eye