Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



How to implement a simple client interface


Client side session with a server

A client side session is represented by an instance of a class derived from RSessionBase which provides the behaviour for connecting to the server and sending messages to it.

In the following code fragment, the class RCountServ, derived from RSessionBase, represents the client side session with a server, called the count server in this example. Note that sessions are not sharable.

class RCountServ : public RSessionBase
    {
public:
    RCountServ();
    TInt Connect();
    TVersion Version() const;
    TInt Stop();
    TInt SetFromString(TDesC& aString);
    void Increase();
    void Decrease();
    void IncreaseBy(TInt anInt);
    void DecreaseBy(TInt anInt);
    void Reset();
    TInt CounterValue();
    };

The important points are:

The function Increase() would be defined as follows:

void RCountServ::Increase()
 {
 TAny *p[KMaxMessageArguments];
 SendReceive(ECountServIncrease,&p[0]);
 }

SendReceive() is called, specifying an operation code ECountServIncrease and an array of argument pointers, which in this case, is empty. Typically, operation codes are enum values defined in a header file visible to both the client interface and the server.

Note that the function SetFromString() takes a descriptor. It is important to note that the descriptor passed to this function must remain in existence until the server request completes. As, in practice, the server may not run until some arbitrary time after the client issues a request, then the descriptor cannot live on the program stack.