How to implement a client interface with subsessions

Provides code snippets to help you to implement a client interface with subsessions.

A client side subsession is represented by an instance of a class derived from RSubSessionBase which provides the behaviour for:

  • creating a subsession in the server

  • sending messages to the subsession.

In the following code fragment, taken from the example that can be found at ...\examples\Base\IPC\ClientServer\complex, the class RCountSubSession, derived from RSubSessionBase, represents the client side subsession with a server (in the example the server is also referred to as the count server). The assumption is made that the client has already established a session with the server as represented by the RCountSession class.

class RCountSubSession : public RSubSessionBase
    TInt Open(RCountSession& aServer);
    TInt SetFromString(const TDesC& aString);
    void Close();
    void Increase();
    void Decrease();
    void IncreaseBy(TInt anInt);
    void DecreaseBy(TInt anInt);
    void Reset();
    TInt CounterValue();
class RCountSession : public RSessionBase
    TInt Connect();
    TVersion Version() const;
    TInt ResourceCount();
    void Close();
    RThread iServerThread;    

The important points in this example are:

  • Open() creates a subsession within the client-side session. A reference to the client-side session is specified as the function's single argument. The function calls RSubSessionBase::CreateSubSession() which, in turn, causes a server side subsession object to be created and its handle number to be returned.

  • Client subsession interface functions, such as CounterValue(), send a specific message to the server.

    TInt RCountSubSession::CounterValue()
        TInt res = KErrNotFound;
        TPckgBuf<TInt> pckg;
        if (SubSessionHandle())
              // Note that TPckgBuf is of type TDes8
            TIpcArgs args(&pckg);
            SendReceive(ECountServValue, args);
              // Extract the value returned from the server. 
            res = pckg();
        return res;        
  • Close() closes the subsession.


  • The operation code passed to RSubSessionBase::CreateSubSession() must be interpreted by the server as a request to create a subsession.

  • When sending a message to the server with a call to RSubSessionBase::SendReceive(), only three arguments can be passed . This function always uses the fourth argument to hold the client subsession handle number which is used to identify the corresponding server side subsession object. The message arguments are subsequently passed to a call to RSessionBase::SendReceive().

  • The operation code passed to RSubSessionBase::CloseSubSession() must be interpreted by the server as a request to close the subsession.