socket.io-client icon indicating copy to clipboard operation
socket.io-client copied to clipboard

Socket.IO client ignores the specified port on initialization

Open ekr3peeK opened this issue 3 years ago • 0 comments

You want to:

  • [x] report a bug
  • [ ] request a feature

Current behaviour

At the moment, I am trying to create a new SocketIO.Client from the browser. My application is accessible on a non-standard X port (in the developement version), and I have an additional node server running on another Y port. I am trying to call the following method to connect to the socket server from the client interface:

import io from 'socket.io-client';

const config = {
    hostname: document.location.hostname,
    port: Y,
    secure: true
}

const socket = io(config);
console.log(config);

I am unable to connect to the socket server, as apparently, the io function updates my configuration so that it points to the same port X that my browser window uses. My console log, at the end provides the following results:

hostname: "hostname here"
path: "/socket.io"
port: X
secure: true

Everything is correct, except the port, which gets overriden to the port on which I accessed my hostname. If I check in my browsers network tab, I can see that a request is being made to: hostname:X/socket.io?...

If I pass an exact url with port to the io function, instead of the object configuration, this works as expected, so the problem is 100% on the client side of the things.

Expected behaviour

I would except, that if I specify a port in the config, the network request which tries to connect should go to the specified port, instead of the current port used.

Setup

  • OS: Server is running on a Centos 8
  • browser: Tested in a client with Firefox 80.0.1 (64-bit)
  • socket.io version: 2.3.0 (both the client and the server)

ekr3peeK avatar Oct 14 '20 11:10 ekr3peeK