×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    12

    Symbian Server, Active Objects and Clients help

    Hi,

    I've been writing an application for a couple of weeks now and have dived into the server/client architecture, and after reading many examples and web-sites, I still have some outstanding questions regarding the initial flow and how to initialize everything.

    I would like my application, when it starts, to start the server and a timer, that fires every 15 minutes with a request (to sync with a server). So far, I have implemented the server and understand the classes I can use for the timer, my question is how to start everything. I see three options.

    1.) Put the main in the server, which in ConstructL() will start the CActive object MyTimer. My problem here is that I'm not sure if MyTimer should be a 'client' or a straight active object. Also, the server will wait for the timer to return before calling the active scheduler to start, yet my client implementations start the server if it isn't started.

    2.) Put the main in the client, and always start the timer client, which starts the server.

    3.) Put the main into a separate class which will start the server and the client.

    Please help, as I've been staring at various website for days and can't really find a good implementation on how the client and server get started (minus the test apps, but I only want one e32main.)

    Thanks.

  2. #2
    Regular Contributor
    Join Date
    Apr 2008
    Location
    India
    Posts
    477

    Re: Symbian Server, Active Objects and Clients help

    As u r saying that the client will actually synch with the server... So putting the timer at client side will be good idea....

    second thing... ur fire event is after 15 minute.... and if ur sever is not very heavy process then i suggest u to close the server (Close the sub session) after each synchronization... and again after 15 minute start the server and synch with it....

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    48

    Re: Symbian Server, Active Objects and Clients help

    another idea:-

    let the client start the server when ever the client starts.
    Let the client register for a 15 min update from the server on an asynchronous basis.
    Once the client gets an update, re-register for an update.Keep this loop continuing as long as your client needs the updates. This way, you can make the server generic i.e., the server shall itself sync with a client on a periodic basis or atleast send client a message for syncing so that the client can depend on server for sync message. This way your timers will be maintained/managed by the server and client need not bother about creating timers, allocating active objects etc. One active object on the client side waiting for Server sync message should be neat and manageable.

    Once the server side, accept 15 minute update(or you can make it more generic i.e, customized time period from the client say 16 mins or 20 mins etc) registration from the Client but if a client dies, ensure to clean its resources on the server side, and check if any more clients are exsiting, if no then shut down. This way you can optimize your application.

  4. #4
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: Symbian Server, Active Objects and Clients help

    Are you using "server" in two difference contexts within the same sentence here? Are you talking about a server external to the device (that you are syncing with) as well as a Symbian OS server?

  5. #5
    Registered User
    Join Date
    Dec 2008
    Posts
    12

    Re: Symbian Server, Active Objects and Clients help

    Hi,

    I do think I used server in two different contexts, so let me be a bit more concrete.

    I need the S60 Server to talk with an External "Cloud" Server (Sync calendar events). Basically, I'm hoping for 'polling' functionality since the external server does not support push notifications.

    I'm still on the learning curve of this architecture, but would the following work?

    I have the server start itself, and during its construction (before calling the scheduler to start), it constructs an active object from CPeriodic, and another Active Object for my cloud syncing. Every time the CPeriodic timer expires, it will call back into a function that will tell the other active object to sync. I believe this would allow all these to occur asynchronously, so that when I do hook up a UI as a 'client', these can happen in the server asynchronously.

    I came about this thinking making a client for a timer may be overkill, and the only client I may really need is a UI (let the server have active objects for syncing with cloud servers).

    So here is the problem I am having:
    In my static RunTheServer(), I install the active scheduler, then create a new server.

    ...
    CActiveScheduler::Install(scheduler);

    // create the server
    CMyServer::NewLC();
    ...

    NewLC() calls the constuctor, push it on the stack, and then call ConstructL(). In ConstructL() I have something that looks like this:

    StartL(KServerName);
    iShutdown.ConstructL();
    iShutdown.Start();
    MyTimer= CPeriodic::NewL(CActive::EPriorityIdle);
    gConsole->Printf(KStartingTimer);
    MyTimer->Start(iTickInterval,iTickInterval,TCallBack(Tick, this));
    }

    After all this returns it does CActiveScheduler::Start()

    When I run this on the emulator, the server shuts down immediately after CActiveScheduler::Start(), by which I mean it reaches the end of the program. If I remove the MyTimer code, it doesn't. I don't really know what is going wrong here, or if the Timer is somehow shutting down the CActiveScheduler. Any help?

  6. #6
    Registered User
    Join Date
    Dec 2008
    Posts
    12

    Re: Symbian Server, Active Objects and Clients help

    Hi,

    I did some debugging and it appears my CShutdown is being called, but I have no clue why.

    I have the following information on CShutdown:

    "this represents a timer that is started before the first client has connected, and after the last client has disconnected. The timer is stopped once the server has at least one client. If the server has no clients, then there is 2 second interval before the server terminates. This is implemented as an active object."

    I'm not entirely sure why the program runs fine w/o the timer code, but then shutdowns when I start the timer.

    Thanks!

  7. #7
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: Symbian Server, Active Objects and Clients help

    CShutdown isn't a class that is part of the OS, you must have based your code on an example? However the use of it in the example code and what you want to do with your code obviously will not match up. WHere did you get the quote about the use of CShutdown from? Understand what that example is doing and if it is relevant to your own needs.

    If the shutdown object expires after 2 seconds then that is why your program is terminating.

    Best thing to do is find a good reference source for servers and understand all about them, i.e. read the Symbian OS Explained book (though bearing in mind it was published before OS 9), or read about servers from the SDK or other sources.

    You would not make a timer class a client of a server.

    In particular you need to find out about the difference between transient and system servers, and how they are started/stopped etc. You need to consider who/how is going to start your server and if/when it will stop.
    You also need to consider is your server will be tied to the lifetime of the UI or not. If yes and if the UI will be the only client then maybe it doesn't need to be a server. If the server's lifetime is going to be independent of the lifetime of the UI is it going to run forever once its been started? If not when/who/how is going to stop it?
    If the server is supposed to run forever but it crashes, how are you going to start it again?
    You said your server starts itself, but something can't magically start, what is the trigger for starting the server?

    You need to answer all these sorts of questions first before you can start to design and implement it to meet your requirements.
    Last edited by hotcheese; 2009-02-03 at 20:02.

  8. #8
    Registered User
    Join Date
    Dec 2008
    Posts
    12

    Re: Symbian Server, Active Objects and Clients help

    Thanks for the response, I'll try to grab this book and read it:

    First the immediate confusion! I removed CShutdown functionality and it works!

    I have been using the following for reference:
    http://www.symbian.com/developer/tec...ver.guide.html

    So...I still don't understand why CShutdown is being called when I start the timer VS when I don't. If I'm looking at the server/client architecture, after I start the shutdown server, and call CShutdown->start, I would think it would shutdown after i start the active scheduler regardless of starting myTimer. I guess I am missing something in this regard.

    Almost every example I've looked at so far, and from the books I have read, have been focused on Transient servers. But it seems what I want from the above is for the server to start itself, which would be a system server. My understanding to do this is to wrap the .exe around the server (main enters server) and to load on auto-start. All of which I have found a pletora of information on, and am currently having the E32Main in my server, which works OK for emulator testing.

  9. #9
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: Symbian Server, Active Objects and Clients help

    There are mechanisms for starting something on installation or on boot up that are probably the plethora you mention.

    "So...I still don't understand why CShutdown is being called when I start the timer VS when I don't. If I'm looking at the server/client architecture, after I start the shutdown server, and call CShutdown->start, I would think it would shutdown after i start the active scheduler regardless of starting myTimer. I guess I am missing something in this regard."

    I'd have to study all the code to answer that, but if the shutdown object is itself a timer which results in termination once the timer expires then your comments above are correct and you're not missing something with your general line of thinking.

    P.S.
    When using callbacks in combination with active objects, the callback has to be brief, i.e. not do any lengthy processing, all it should do is inform something to do something then return immediatly.
    If using CPeriodic is a bit messy you can consider using CTimer instead perhaps.

  10. #10
    Registered User
    Join Date
    Dec 2008
    Posts
    12

    Re: Symbian Server, Active Objects and Clients help

    Thanks Hotcheese.

    Things are progressing and we're ready to start integrating the GUI. The thought is that the GUI would be a .dll

    So here's the thought:

    When the timer expires, and for some reason authentication has failed, I would launch the UI .dll with that reason (so it prompts the user to enter their password/username).

    Question 1) Does launching a DLL block the server? Do I need to do this in a seperate thread?

    I have a GUIClient.cpp which has the E32DLL(TDLL Reason) which turns around and calls
    "return EikStart::RunApplication( NewApplication );"

    Question 2) I Would like the UI to have a client connection with the server, but I don't know where a RSessionBase Class would fit.

    We _THINK_ We can call our APPUI like this and control the UI and server communications like this:
    class S60AppUi : public CAknViewAppUi, RSessionBase

    Will this work?

    Thanks!

  11. #11
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: Symbian Server, Active Objects and Clients help

    Hi

    You mention launching the UI from server, and the UI being a client of the server. The two things are somewhat at odds with each other.


    Usually a UI would be a client of a server, as you are creating a sync program lets assume your server has the method to start a sync.

    Then when the UI is launched it would create a session with your server and then call Sync(). If authentication is needed it can be Sync(username, password) as params.

    However if the username/password need to be passed at a later stage, then a callback API could be defined, and when the server needs this info from the UI it is done via a callback (important note - a callback cannot go accross a process boundary, the callback is virutal and is between the client side part of your server and the UI, the 'callback' between the client side and server side of your program is done using TRequestStatus). This probably sounds confusing, you need to remember that when you write a server there are effectively two parts two it, one which sits in the client process and one which sits in the server process. I might have confused you so find a good bood about client/server programming.



    So there's no need for your server to actually launch a UI, that would be a bit out of the ordinary.

    Maybe your next question though is what if your server is permanently running and is doing something and needs to get username/password but at that point the UI is not running. The tidy way to do this is using notifiers, see what documentation you can find about the RNotifier class, it is effectively a way of non UI code launching a simple UI such as a dialog to display some info to the user and get some input back from them.

  12. #12
    Registered User
    Join Date
    Dec 2008
    Posts
    12

    Re: Symbian Server, Active Objects and Clients help

    Thanks again for your help.

    I've started research the RNotifier class and am not able to find anything where a user can type in a "username" for input, unless I want to right an extended Notifier, which looks like it requires a client/server interaction, so I'm a little puzzled why not just use the UI.

    The one example I found about writing an extended notifier is incomplete and I couldn't find much in S60 OS Explained or in the Quick Recipes.

    Do you know of any web-resources or examples?

  13. #13
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: Symbian Server, Active Objects and Clients help

    Hi

    The useages of them I am familiar with I wouldn't be able to share. If you can't find any good reference material then it may be quicker to go with something else.

Similar Threads

  1. mulitple clients
    By ja_calulot in forum Bluetooth Technology
    Replies: 6
    Last Post: 2007-09-13, 11:28
  2. Active objects in EXE second thread
    By inguvaseshu in forum Symbian Networking & Messaging (Closed)
    Replies: 8
    Last Post: 2006-08-10, 05:35
  3. How to send bitmaps?
    By Leicester22 in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2004-09-03, 13:20
  4. multiple clients
    By ja_calulot in forum Bluetooth Technology
    Replies: 1
    Last Post: 2003-11-05, 10:53
  5. multiple clients
    By ja_calulot in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2003-11-05, 09:34

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×