Waiting for client connections?

RCF support and general discussion.
Post Reply
Rectangle
Posts: 3
Joined: Mon May 06, 2013 9:35 pm

Waiting for client connections?

Post by Rectangle »

While following the tutorial code posted here, I noticed the section in the server code which says "Wait for clients to create callback connections" does not provide any examples of how this can be achieved.
I assume I need to create some sort of loop which actively checks for a connection, but how?
I also noticed the enumerateSessions function, which I assume could aid in this, but there is no documentation available on how to properly use it.

So how can I make the server wait for a client to connect to it?

jarl
Posts: 238
Joined: Mon Oct 03, 2011 4:53 am
Contact:

Re: Waiting for client connections?

Post by jarl »

You need to use RcfServer::setOnCallbackConnectionCreated() , to get notified of whenever a callback connection is created. The sample code in the User Guide does this:

Code: Select all

RCF::RcfServer server( RCF::TcpEndpoint(0) );
server.setOnCallbackConnectionCreated(onCallbackConnectionCreated);
server.start();
From within onCallbackConnectionCreated(), your application can take whatever action it needs to with regards to the callback connection.

To get the server to wait, just make sure your application doesn't destroy the RcfServer object. Typically you would create the RcfServer and call start() on the main thread, and then the main thread would go into an application specific loop, waiting for a shutdown to be initiated. When your application decides that it's time to shut down, you stop the server and destroy it.

If you need a way to hang around indefinitely after the server has started, you can do this:

Code: Select all

RcfServer server(...);
server.start();
server.waitForStopEvent();
Kind Regards

Jarl Lindrud
Delta V Software
http://www.deltavsoft.com

Rectangle
Posts: 3
Joined: Mon May 06, 2013 9:35 pm

Re: Waiting for client connections?

Post by Rectangle »

Oh I see... I had my thoughts mixed up. For some reason I thought it ran on the same thread.
But after throwing in a simple Sleep() command on the server's main thread (in place of "Wait for clients to create callback connections") and connecting a client to it during that time, I can confirm that the code runs exactly as expected.
Thank you for clearing this up.

Post Reply