Timing over socket connection

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

trevix
Posts: 962
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: Timing over socket connection

Post by trevix » Wed Jan 11, 2023 8:53 pm

Not until the buffer is full on the receiving end. If the buffer is full, no more data can be written until some data is read
Should not be my case, since the data is less then 100k and regularly read by the receiving end.
If you try to read an empty buffer you'll just get an empty value unless you told it how much to read or to read until it encounters a specified chunk, in which case it will wait until the specified amount of data is received or until the chunk is encountered.
I use chunk at the end of the data.

Code: Select all

read from socket p_Socket until kEndOfFile with message "chatServerMessageReceived"
So if I do such a read and there is no data to read, the script will hang for a SocketTimeoutInterval?
I can then clear the buffer with a

Code: Select all

read from socket p_Socket
without specifying the kEndOfFile?
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

Cairoo
Posts: 107
Joined: Wed Dec 05, 2012 5:54 pm

Re: Timing over socket connection

Post by Cairoo » Wed Jan 11, 2023 9:03 pm

when doing such a read without specifying a callback message, the script would hang until a socket timout. In your case you did specify a callback message, so the script continues immediately and the callback handler will be called later whenever the data has arrived.

Cairoo
Posts: 107
Joined: Wed Dec 05, 2012 5:54 pm

Re: Timing over socket connection

Post by Cairoo » Wed Jan 11, 2023 9:18 pm

trevix wrote:
Wed Jan 11, 2023 8:53 pm
I can then clear the buffer with a

Code: Select all

read from socket p_Socket
without specifying the kEndOfFile?
Yes that's how you'd read from the buffer to clear it of data you'd like to discard. But then perhaps you'd do it in a repeat loop until it is empty, just to be sure.

Code: Select all

read from socket p_Socket
repeat while it is not empty
   read from socket p_Socket
end repeat
Edit: After a socket timeout I think it's safe to assume there's no more data to be read, because it was waiting for more data that did not arrive.
But then the data could still be on its way so there's no guarantee the buffer won't contain data shortly after the timeout.

trevix
Posts: 962
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: Timing over socket connection

Post by trevix » Fri Jan 13, 2023 5:19 pm

Read from socket p_Socket
cannot be compiled because does not have a termination condition specified.
The script editor does not accept it.
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

Cairoo
Posts: 107
Joined: Wed Dec 05, 2012 5:54 pm

Re: Timing over socket connection

Post by Cairoo » Mon Jan 16, 2023 8:19 am

:oops:

I didn't test it before posting. I've only ever used it with a callback message and it turns out that the form without a condition can only be used with a callback message.

Code: Select all

read from socket p_socket with message dataReceived
I wanted to blame it on the dictionary. This time I can't.

trevix
Posts: 962
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: Timing over socket connection

Post by trevix » Mon Jan 16, 2023 11:34 am

Yeah, adding "with message dataReceived" to all my read solved all my problems apparently.
Thanks
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Timing over socket connection

Post by mwieder » Mon Jan 16, 2023 6:57 pm

Thankfully the script compiler is smart enough to catch the error.
And yes, the "read from socket" command needs either an "until xxx" clause or a callback mechanism.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”