N
N
Nikolay Alekseev2020-06-01 21:06:55
Node.js
Nikolay Alekseev, 2020-06-01 21:06:55

How to get parameters from client when connecting on server side WebSocket in nodeJs?

Greetings!

There is a simple web socket server. He doesn't know how to do anything yet.

webSocketServer.on('connection', function (ws) {
  let id = lastId++;
  clients[id] = ws;
  console.log("новое соединение " + id);

  ws.send(JSON.stringify({"You are": "connected"}));

  ws.on('message', function (message) {
    console.log('получено сообщение ' + message);
  });

  ws.on('close', function () {
    console.log('соединение закрыто ' + id);
    delete clients[id];
  });
});


But from the client side, the connection does not just happen as
client.connect('ws://localhost:8081/', 'echo-protocol');


And with the parameters, like this:
client.connect('ws://localhost:8081/?some_id=12345', 'echo-protocol');

This is a mandatory condition, which, unfortunately, I can not bypass.
Is it possible to get this very some_id somehow on the server side?

Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Pautov, 2020-06-01
@VariusRain

https://stackoverflow.com/questions/17301269/can-w...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question