Real Software Forums
http://forums.realsoftware.com/

EasyTCPSocket.WaitForMessage
http://forums.realsoftware.com/viewtopic.php?f=2&t=44400
Page 1 of 1

Author:  MadDoc [ Fri Jun 15, 2012 1:31 pm ]
Post subject:  EasyTCPSocket.WaitForMessage

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?

Author:  MadDoc [ Sat Jun 16, 2012 3:47 pm ]
Post subject:  Re: EasyTCPSocket.WaitForMessage

Any ideas guys?

Author:  taylor-design [ Sat Jun 16, 2012 7:59 pm ]
Post subject:  Re: EasyTCPSocket.WaitForMessage

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.

Author:  MadDoc [ Mon Jun 18, 2012 2:41 am ]
Post subject:  Re: EasyTCPSocket.WaitForMessage

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...

Author:  msssltd [ Mon Jun 18, 2012 3:45 am ]
Post subject:  Re: EasyTCPSocket.WaitForMessage

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]

Author:  taylor-design [ Mon Jun 18, 2012 4:04 am ]
Post subject:  Re: EasyTCPSocket.WaitForMessage

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.

Author:  MadDoc [ Mon Jun 18, 2012 6:49 am ]
Post subject:  Re: EasyTCPSocket.WaitForMessage

@taylor-design:

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

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/