Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Aug 17, 2019 5:40 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: EasyTCPSocket.WaitForMessage
PostPosted: Fri Jun 15, 2012 1:31 pm 
Offline
User avatar

Joined: Wed Oct 05, 2005 1:21 pm
Posts: 515
Location: United Kingdom
I have a question about the WaitForMessage method of the EasyTCPSocket that isn't clear in the language reference.

The client (a game) I'm working on needs to send messages to the server and wait for its response until proceeding. I've been doing something along the lines of (pseudocode):

MySocket.SendMessage( MyCommandID, MyMessage )
if MySocket.WaitForMessage( TheCommandIWant, kTimeoutInSecs ) = "The Answer" then
// do something
else
// do something else
end if


Does the WaitForMessage method always wait for the specified timeout period (in above example, kTimeoutInSecs) to elapse before proceeding? I *think* that's what it's doing but the LR isn't clear. If this is the case, any suggestions for a custom method I can call that will proceed as soon as the server sends the message rather than waiting for kTimeoutInSecs?

Basically, what seems to be happening is that I've set the Timeout to be 10 seconds and the client waits 10 seconds before executing the code above. What I really need is to send the server a message and wait for it's response. If it responds in 0.5 seconds then I'd like to proceed but if it hasn't responded within 10 seconds then not.

Is this possible?

_________________
Gorgeous REALbasic controls from Figa Software | My Flickr | My Blog
11" MacBook Air 1.8Ghz i7, 4GB RAM, OSX 10.8.2, RB 2012 r1.1 Pro | iPhone 4S 32GB | Nikon D60


Top
 Profile  
Reply with quote  
 Post subject: Re: EasyTCPSocket.WaitForMessage
PostPosted: Sat Jun 16, 2012 3:47 pm 
Offline
User avatar

Joined: Wed Oct 05, 2005 1:21 pm
Posts: 515
Location: United Kingdom
Any ideas guys?

_________________
Gorgeous REALbasic controls from Figa Software | My Flickr | My Blog
11" MacBook Air 1.8Ghz i7, 4GB RAM, OSX 10.8.2, RB 2012 r1.1 Pro | iPhone 4S 32GB | Nikon D60


Top
 Profile  
Reply with quote  
 Post subject: Re: EasyTCPSocket.WaitForMessage
PostPosted: Sat Jun 16, 2012 7:59 pm 
Offline

Joined: Wed Mar 22, 2006 11:15 am
Posts: 712
Location: Southern California
Its been a while since I've used EasyTCPSocket, but I don't think it waits the full timeout period if a message has been received.

You're actually seeing this behavior in your code? It's waiting 10s when the message was received in, say, <1s?

Knowing what you're trying to do, I don't know if I would recommend EasyTCPSocket in any case. It locks you into a design pattern where your code blocks while waiting for a server response. It should return immediately once the server has responded, but if the server is taking its sweet time your app is frozen. Regular TCPSockets use events so your code does not block. I realize that means defining your own message protocol, but it's something to consider.

_________________
Daniel L. Taylor
Custom Controls for Real Studio WE!
Visit: http://www.webcustomcontrols.com/


Top
 Profile  
Reply with quote  
 Post subject: Re: EasyTCPSocket.WaitForMessage
PostPosted: Mon Jun 18, 2012 2:41 am 
Offline
User avatar

Joined: Wed Oct 05, 2005 1:21 pm
Posts: 515
Location: United Kingdom
I'm trying to restructure my networking code so that it is fully event-driven (rather than the synchronous model I currently have implemented) but it's not easy.

I've been doing more research and I think I may switch to the EasyUDPSocket class. My feelings being that this removes the connection limit restrictions I would face with TCP and is faster since there is no connect-disconnect procedure...

_________________
Gorgeous REALbasic controls from Figa Software | My Flickr | My Blog
11" MacBook Air 1.8Ghz i7, 4GB RAM, OSX 10.8.2, RB 2012 r1.1 Pro | iPhone 4S 32GB | Nikon D60


Top
 Profile  
Reply with quote  
 Post subject: Re: EasyTCPSocket.WaitForMessage
PostPosted: Mon Jun 18, 2012 3:45 am 
Offline
User avatar

Joined: Fri Oct 28, 2005 7:05 am
Posts: 565
Location: Emsworth, UK
MadDoc wrote:
I've been doing more research and I think I may switch to the EasyUDPSocket class. My feelings being that this removes the connection limit restrictions I would face with TCP and is faster since there is no connect-disconnect procedure...

I very much expect you would be swapping one set of problems for another. Your choice of protocol should be based on the needs of your application and whatever problems your choice throws up, are likely to be the problems you need to overcome.

Network programming is generally unforgiving at design time. Poor design leads to a poor application. That is how it is, unfortunately.

UDP is faster, because it does not have a session overhead. UDP is not reliable, because it does not have a session overhead. UDP does not easily pass through NAT routers and SPI firewalls easily, because it does not have a session overhead. So on and so forth.

In real world use, the speed advantage of UDP over TCP is non-existent to tiny, unless you happen to be shifting an awful lot of packets.

I do not know exactly what you mean when you say "connection limit restrictions" TCP has connection limits but if you are expecting to run into them, RB would be a poor choice of tool to develop the project in the first place.

[edit: clarified]

_________________
Yes it's me in the avatar


Last edited by msssltd on Mon Jun 18, 2012 5:06 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: EasyTCPSocket.WaitForMessage
PostPosted: Mon Jun 18, 2012 4:04 am 
Offline

Joined: Wed Mar 22, 2006 11:15 am
Posts: 712
Location: Southern California
msssltd wrote:
I do not know exactly what you mean when you say "connection limit restrictions" TCP has connection limits but if you are expecting to run into them, RB would not be a poor choice of tool to develop the project in the first place. You might be talking about restrictions specific to the EasyTCP classes, which I never use, so can not comment.


He's referring to connection limits per server, i.e. limits at the OS, TCP stack, or performance level which he will run into with any language.

Otherwise, spot on post. MadDoc - knowing what you're trying to do I would stick with TCP and not move to UDP.

_________________
Daniel L. Taylor
Custom Controls for Real Studio WE!
Visit: http://www.webcustomcontrols.com/


Top
 Profile  
Reply with quote  
 Post subject: Re: EasyTCPSocket.WaitForMessage
PostPosted: Mon Jun 18, 2012 6:49 am 
Offline
User avatar

Joined: Wed Oct 05, 2005 1:21 pm
Posts: 515
Location: United Kingdom
@taylor-design:

I've just PM-d you with a bit more information about the game if you're interested...

_________________
Gorgeous REALbasic controls from Figa Software | My Flickr | My Blog
11" MacBook Air 1.8Ghz i7, 4GB RAM, OSX 10.8.2, RB 2012 r1.1 Pro | iPhone 4S 32GB | Nikon D60


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group