I am currently writing an application that does substantial communication with a third party remote server using TCP. I run into a problem when I have authenticated the connection and begin passing information between the client and the server. I am having a problem determining exactly when the remote server has finished sending all of its data, and is ready to receive another command.
At first I tried
Code: Select all
(set 'contents "")
(while (net-receive socket 'buf 1024)
(set 'contents (string contents buf))
)
Unfortunately when the net-receive reaches the end of the data it will "hang" and is basically listening until the server sends it more info (which it won't).
I tried a second test as follows
Code: Select all
(set 'contents "")
(while (net-receive socket 'buf 1024)
(print "peek: " (net-peek socket) "\n")
(set 'contents (string contents buf))
)
I did this because I wanted to see if net-peek would indicate whether or not there was information waiting to be taken off the socket. In many cases it returns the value "0" even though there is information. The only instance where a value was returned is when an initial (net-receive .... 1024) buffer size is exceeded.
I am, then, a little confused on how to determine whether or not my socket has received information from the server. My final idea, if this is truly the case, would be to implement a "timeout" for the listener. If it exceeds a certain time then it is in an endless wait and I can "break" the listen and go back to executing. If this is indeed the approach I need to take can anyone enlighten me on how to implement this sort of timer construct?
Thanks,
-Keatts