client initialization doesn’t seem to be working as documented (4.x)

My server is hosted on virtualized hardware exposed at an endpoint of<id>/

And by default will try to connect to so I need to customize the endpoint used. According to the docs for 4.x:

In the examples above, the client will connect to the main namespace. Using only the main namespace should be sufficient for most use cases, but you can specify the namespace with:

// same origin version
const socket = io("/admin");
// cross origin version
const socket = io("");

So I went with:

const socket = io("/<id>/");

and also tried:

const socket = io("/<id>/");


const socket = io("<id>/");


const socket = io("<id>/");

But the failing polling messages show that it’s trying to connect to the default

I can verify that the socket server is running at the correct endpoint because visiting<id>/ serves a message: {"code":0,"message":"Transport unknown"} and<id>/ serves Socket.IO v4.0.0

What can I do to further debug or fix this?

Edit: Tried with v3 and experienced the same result.


What you’re trying to do is to get Socket.IO to connect to a different path, not a namespace. In short, you should use the path option, like so:

// The string passed as the first argument is the Namespace to use,
// not the path to connect to.
const socket = io("/", {
  // Set the <id> to your actual path ID.
  path: "/<id>/"

Read more about Socket.IO Namespaces here.