Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

TCP Socket write and read

$
0
0

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.


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>