Problem with "read from socket"

Dar Scott dsc at swcp.com
Mon Jun 28 14:32:41 EDT 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"

or

    read from socket socket1 with message "gotData"

The above blocking method can be used like this:

on mouseUp
   constant sid = "127.0.0.1:13"
   put empty into field "Log"
   open socket sid
   repeat 10000
     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
   end repeat
   close socket sid
end mouseUp

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".

Dar Scott



More information about the use-livecode mailing list