Answer the question
In order to leave comments, you need to log in
How to make a function wait for a response from a WebSocket server?
There is a function that should send a websocket request to the server and receive a response in 10-15 seconds
function getData(){
var sock = io("https://server.com");
var out = "";
sock.on("mess", function(data){out = data.message});
sock.emit("send", {text: "Hello, world!"});
return out;
}
Answer the question
In order to leave comments, you need to log in
You are doing something wrong. Here is asynchronous programming, you connect to a websocket, send a signal to perform an action and that's it, then just catch the signal (which will be sent by the first signal handler) that the action is completed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question