Socket read problems

Len Morgan len-morgan at crcom.net
Thu Oct 7 20:22:02 EDT 2010


  I'm trying to read data from a MODBus/TCP controller and having some 
issues with the timing of the read command.  I request a block of 
registers from the slave and it returns the requested bytes and header 
just fine and very quickly.  In order to read everything right, I have 
to first read the first 6 bytes of the header to know how many bytes are 
to follow.  Once I know that, I do a read from socket tSock for <bytes> 
characters.  Note that ALL of the characters have been received in a 
single packet so once I read the 6 bytes, the rest of the data is 
already in the socket buffer.

The problem I have is when I do the second read, the read command blocks 
for the socketTimeoutInterval before continuing.  It doesn't matter what 
I set it to, it will wait that long before continuing.  I tried catching 
the socketTimeout message but that message is never sent, even when I 
set the socketTimeoutInterval to 5 milliseconds!

I am not using the read ... with message form of the command since I 
want the handler to wait until all the bytes have been received before I 
move on.  Has anyone else seen this?  Have I missed something in the 
documentation or could this be something in the Windows code that 
handles sockets?

Any help would be appreciated!

len morgan



More information about the use-livecode mailing list