Problem with "read from socket"
dsc at swcp.com
Mon Jun 28 13:32:41 CDT 2004
On Jun 28, 2004, at 1:38 PM, maxence.bernard at ensi-bourges.fr wrote:
> I encounter a strange result in my program. I have a program like this
> answer "something"
> read from socket socket1 for 2
> answer "something2"
I don't usually read without the message parameter. Since I don't
usually use the blocking style, I might get this a little off.
With blocking you can use this:
read from socket socket1 until empty
That means read until the buffer is empty; it does not wait until the
socket is closed.
With non-blocking you can use this:
read from socket socket1 until empty with message "gotData"
read from socket socket1 with message "gotData"
The above blocking method can be used like this:
constant sid = "127.0.0.1:13"
put empty into field "Log"
open socket sid
read from socket sid until empty
put "result: " & the result & lf after field "Log"
put "data: " & it & lf after field "Log"
if it is not empty then exit repeat
close socket sid
Since you want to read two bytes, modify that to accumulate bytes until
you get two or you timeout.
Or your might want to switch to "with message".
More information about the use-livecode