S
S
Sergey Sokolov2020-05-03 18:51:27
JavaScript
Sergey Sokolov, 2020-05-03 18:51:27

How to open several different WebSocket connections to the same server/port from NodeJS?

To test the WS application, it was necessary to open several connections in parallel:
1 as an admin, several as users. So far, I have done the entire test in one script: admin and user objects are created,
each creates its own WS instance :

const WebSocket = require('ws');

this.ws = new WebSocket(`ws://${this.server_ip}:${this.server_ws_port}`);


But it turns out that there is only one connection. From the server's point of view, there is only one connection, and all commands fall into it. From all "customers".

WS server, if it matters, on Swoole. I connect directly from the same server where it is running, on 127.0.0.1

How to make connections to be different, albeit from the same process and to the same ip/port?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mitya_k, 2020-05-03
@mitya_k

It looks like you don't need a second connection, you just need to check on the server side for authorization (cookie, token or whatever) when the client connects.
For example, iostreamer.me/ws/node.js/jwt/2016/05/08/websockets...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question