Bob -

Don't use EOF. It's broken since forever ago.

I've done both of the following methods with success:

-- either --

End your data stream with a CR, and then on the receiving end "read from socket XYZ for 1 line". This assumes that the data stream itself doesn't contain any CRs. I normally base64-encode the data stream, then replace CR with empty in the encoded string. This doesn't interfere with base64Decoding on the receiving end - it'll still work fine.

-- or --

Make line 1 of your data stream an integer that is the number of bytes in line 2 of your data stream
Make line 2 of your data stream the data you want to send

Then on the receiving end, do a two-step:
- read from socket XYZ for 1 line
- put it into tDataLength
- read from socket XYZ for tDataLength bytes


That's all I got :-)
Phil Davis



On 4/4/23 1:47 PM, Bob Sneidar via use-livecode wrote:
I have sockets working in my File Server Agent, but only using non-blocking calls, that is using 
"with message". Removing the "with message" bit does not return any response 
from the server agent.

For instance I send a payload using
write payload to socket tSocket with message "messageReceived"
The messageReceived handler gets triggered, and I can then
read from socket tSocket until EOF -- or other delimiter
it will then contain the response from the File Server Agent.

If however I use
write payload to socket tSocket -- blocking
read from socket tSocket until EOF -- or some other delimiter doesn't matter

the call times out and nothing ends up in the it or result variables.

I can (and have) made the non-blocking method work, but that means I have to 
send all the files I want to transfer all at once, because if I send them one 
at a time, I need to know if the last transfer succeeded before continuing.

Does anyone have an example of a blocking socket server? The example in 
Livecode Lessons really only focuses on non-blocking calls.

Bob S


_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


--
Phil Davis
(503) 307-4363


_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to