0

i got this code example from npm that im using for one of my projects :

const WebSocket = require('ws');

const ws = new WebSocket('ws://www.host.com/path');

ws.on('open', function open() {
  ws.send('something');
});

ws.on('message', function incoming(data) {
  console.log(data);
});

my issue: after socket is open im sending command message with ws.send('{command:123}') what im expecting is to get the message direct for this command and then i want to send another command and get the message from that new command but separately .

at the moment when im sending command and there is more then one it display only one message but with both of the command responses. so what im trying to accomplish is:

send command receive message do something with that message send another command do something with the new message

i hope that i explained well. thanks

Assaf Schwartz
  • 119
  • 1
  • 7
  • Maybe it should helper you https://stackoverflow.com/questions/4445883/node-websocket-server-possible-to-have-multiple-separate-broadcasts-for-a-si – BENARD Patrick Apr 04 '20 at 10:18
  • no it dosent , im not working on chat or working with users, im working as a client in front of web socket , i need to send command and get the response immediately and use it, then i want to send other command and many more and use each response and not wait for one response in total. thanks – Assaf Schwartz Apr 04 '20 at 11:08

0 Answers0