Hi, have a question about how to wait to read and write using sockets.
I need establish connection with a server using sockets, then send some data and wait for response, (read data), then send data again again.
Now i use setTimeOut, something like that:
setTimeout(function() { connect(); setTimeout(function() { sendData(); setTimeout(function() { reciveData(); setTimeout(function() { sendData(); }, 2000); }, 2000); }, 2000); }, 2000);Works fine, but my problem is when i lost connection or my connection is low, the timeout doesn't work because i need to wait the response from the server before the send data again and if my connection is low, the 2 secs of setTimeOut are not enough to read the data from the server if i have delay.
Anyone knows the best way to do that?, thank you very much.