Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Jul 18, 2018 11:02 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: TCPSocket and Reading Synchronously
PostPosted: Fri May 13, 2011 6:44 am 
Offline

Joined: Mon Nov 24, 2008 12:25 am
Posts: 155
I have a subclass of a TCPSocket with a "SendPacket" method. I need to wait for a response before I write another packet to the socket. Is it safe to do this in my SendPacket method?
if message = ""  then return

me.write( message )

// Halt further execution of the app and make the socket wait
// here until it receives a response. Timeout after 5 seconds.
dim st as double = Microseconds
do until me.BytesAvailable > 0 or ( Microseconds - st > 5000 * 1000)
me.Poll
loop


Many Thanks!


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocket and Reading Synchronously
PostPosted: Fri May 13, 2011 12:27 pm 
Offline

Joined: Mon Nov 24, 2008 12:25 am
Posts: 155
Ok, after actually debugging the above code, I realized why this wouldn't work.

So, I added a property to my TCPSocket subclass called, "DataIsAvailable" and I set that to True when the TCPSocket.DataAvailable event fires.

My SendPacket method is below. Any thoughts?

Sub SendPacket(Message as String, optional Synchronous as Boolean = True)
if Message = "" then return

if Synchronous then
DataIsAvailable = False
else
DataIsAvailable = True
end if

me.write( Message )

// Halt further execution of the app and make the socket
// wait here until it receives a response.
// Timeout after 5 seconds.
dim st as double = Microseconds
do until DataIsAvailable or ( Microseconds - st > 5000 * 1000)
me.Poll
loop

End Sub


Many Thanks!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group