0

I need to access Web sockets via specific path, I mount my socket.io on the client with a path ('ws') Server code:

var io = require('socket.io')(server, {path: '/notif'});

Client code:

var socket = io('//127.0.0.1:7733/ws/', {path: '/notif'});
socket.connect();

This does not work due to “ws” on client. I suspect it's because I don't have the equivalent on the server (e.g. require server on specific path). (when removing the /rt mount, everything seems to work as expected).

What is the server api to set up ws to listen on specific URL ?

1 Answer 1

3

Are you sure you know what /ws/ in your url is used for?

Here you are asking to connect to the ws namespace. To receive connection for that namespace on the server you have to write:

io.of('/ws').on('connection', function(socket){
  console.log('someone connected');
});

See: http://socket.io/docs/rooms-and-namespaces/

Also you don't need to call socket.connect();

Calling io() or io.connect() will already try to establish connection with the server.

Sign up to request clarification or add additional context in comments.

2 Comments

/ws/ in my case if really just a hint for my load balancer to route the request to the correct server.
Then I think you should have this on your client: io('//127.0.0.1:7733', { path: '/ws/notif' }) and set the same path on the server depending whether or not your balancer rewrites the path

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.