N
N
Nikolay Lapshin2020-01-18 16:30:59
C++ / C#
Nikolay Lapshin, 2020-01-18 16:30:59

Socket.io node js - how to send a message from the server to the client and get a response to it?

I send messages from the node server to the client on electronjs via socket.io.

io.sockets.to(socket_id).json.send({
"msg":"msg"
});

From the client too without problems I send messages to the server.
socket.send({
"msg":msg
});

And how to send a message from the server to the client and immediately receive a response?
Essentially like curl, a post request.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
basrach, 2019-04-12
@basrach

The string means the declaration of a static constructor. Most likely it is empty, or it is defined somewhere else (if it is possible in C++\CLI). Strings:static ConvertedString();

private:
      ConvertedString(const wchar_t const * data, int ActualLength) :
      char_data(data),
      length(ActualLength)
      {
         ...
      }

Regular constructor with access modifierprivate

N
Nikolai Lapshin, 2020-01-18
@madmaker

I figured it out myself.

socket.emit("eventName", "argString", function(data) {
   console.log("data");//Вернет test
});

socket.on('eventName', (argString, fn) => {
   fn('test');
});

It turns out that we just send the name of the callback function from the server to emit, and the client will already execute this function and pass the necessary arguments to it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question