PrevUpHomeNext

Callback Connections

Creating callback connections
Transport protocols

Usually remote calls are made from a client to a server. RCF also implements a callback connection concept, allowing the server to take over a connection and use it to make remote calls back to the client.

Remote calls over callback connections function just like remote calls over regular connections, except that callback connections cannot be automatically re-connected.

On the client-side, to create a callback connection to receive calls on, use RCF::createCallbackConnection():

// Client-side - start a callback server.
RCF::RcfServer callbackServer( RCF::TcpEndpoint(0) );
HelloWorldImpl helloWorldImpl;
callbackServer.bind<I_HelloWorld>(helloWorldImpl);
callbackServer.start();

// Client-side - create callback connection.
RcfClient<I_HelloWorld> client(( RCF::TcpEndpoint(port) ));
RCF::createCallbackConnection(client, callbackServer);

Note that you need a callback server to receive calls through, and a RcfClient<> instance with which to connect to the remote server.

On the server-side, use RcfServer::setOnCallbackConnectionCreated() to receive notification when a callback connection is created, and take control of the callback client transport:

// Server-side - taking control of callback connections.
RCF::Mutex gCallbackTransportMutex;
RCF::ClientTransportAutoPtr gCallbackTransportPtr;

void onCallbackConnectionCreated(
    RCF::RcfSessionPtr sessionPtr, 
    RCF::ClientTransportAutoPtr clientTransportPtr)
{
    // Store the callback client transport in a global variable for later use.
    RCF::Lock lock(gCallbackTransportMutex);
    gCallbackTransportPtr = clientTransportPtr;
}

RCF::RcfServer server( RCF::TcpEndpoint(0) );
server.setOnCallbackConnectionCreated(onCallbackConnectionCreated);
server.start();

Once you have the callback client transport, you can use it to construct an appropriate RcfClient<> instance, and subsequently use that to make calls back to the client:

// Server-side - wait for callback connection to be created.
while (true)
{
    RCF::sleepMs(1000);
    RCF::Lock lock(gCallbackTransportMutex);
    if (gCallbackTransportPtr.get())
    {
        RcfClient<I_HelloWorld> callbackClient( gCallbackTransportPtr );
        callbackClient.Print("Hello World");
        break;
    }
}

Transport protocols configured on the original client-to-server connection are not carried over to the callback connection. If you want to use a transport protocol on the callback connection, it needs to be configured explicitly:

RcfClient<I_HelloWorld> callbackClient( gCallbackTransportPtr );
callbackClient.getClientStub().setTransportProtocol(RCF::Tp_Ntlm);
callbackClient.Print("Hello World");


PrevUpHomeNext