×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Sep 2008
    Location
    India
    Posts
    126

    Question Wants to implement SocketListener using Active Object ....

    Hi all ,

    1. I successfully implemented socket listener by binding entire logic in single function , and that was working fine .

    2. Now I want to implement that logic using Active Object , For that I arrange code as follows ...

    void CListenToPerticularPort::ConstructL()
    {
    CActiveScheduler::Add(this); // Add to scheduler
    User::LeaveIfError(socketServ.Connect());
    User::LeaveIfError(listener.Open(socketServ, KAfInet,KSockStream,KProtocolInetTcp));
    User::LeaveIfError(listener.Bind(addr));
    User::LeaveIfError(listener.Listen(1));
    blank.Open(socketServ);

    1 st try :
    listener.Accept(blank, iStatusForAccept);
    //User::WaitForRequest(iStatusForAccept);

    .... If I put SetActive(); here
    the request returns iStatusForAccept code in RunL which is not equal to "KErrNone"

    Whenever ther is data to read on perticular port then only this will return KErrNone


    2 nd Try :
    blank.RecvOneOrMore(buffer, 0, iStatusForRecv, dummyLength);
    And instead if I put SetActive(); here
    Whenever data is availble to listen iStatusForAccept becomes KErrNone and We can read data is RunL ......
    But In this case I have to use "User::WaitForRequest(iStatusForAccept);" for
    listener.Accept(blank, iStatusForAccept);

    Due to that , Application is in hang state , till availability of data on port .......


    }
    I want to avoid this effect , and wants to make "listener.Accept(blank, iStatusForAccept); async service "

    .......................

    What can I do to achieve so .....????

    Please help if anybody has any idea ...

    Thanks and Regards,
    Kranti

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,752

    Re: Wants to implement SocketListener using Active Object ....

    You have to implement a state machine:
    Code:
    // in .h:
    enum TState {EAccepting,EReceiving} iState;
    
    // in .cpp:
    CActiveScheduler::Add(this); // Add to scheduler
    User::LeaveIfError(iSocketServ.Connect()); 
    User::LeaveIfError(iListener.Open(iSocketServ, KAfInet,KSockStream,KProtocolInetTcp));
    User::LeaveIfError(iListener.Bind(iAddr)); // <--- you should initialize iAddr somewhere
    User::LeaveIfError(iListener.Listen(1));
    iBlank.Open(iSocketServ);
    iListener.Accept(iBlank, iStatus); 
    SetActive();
    iState=EAccepting;
    
    RunL()
    {
        if(iStatus==KErrNone)
        {
            switch(iState)
            {
            case EAccepting:
                iBlank.RecvOneOrMore(iBuffer, 0, iStatus, iDummyLength);
                SetActive();
                iState=EReceiving;
                break;
            case EReceiving:
                // do something with iBuffer
                break;
        }
        else
        {
            _LIT(KPanicFormat,"RunL[%d]");
            TBuf<20> panic;
            panic.Format(KPanicFormat,iState);
            User::Panic(panic,iStatus);
        }
    }
    - when using active objects, never declare own TRequestStatus variables - the Active Scheduler will not know about them, and your code will die
    - when something is wrong, you should check the available error codes.
    Note that User::Panic stuff will not display anything, unless you enable the messages: http://wiki.forum.nokia.com/index.ph...ded_panic_code
    Of course Panic-s are not the best possible solution, since it will kill your application. But for testing, it is ok.

    Also note that RSocket::Accept does not power up any network interface by itself, usually you want to use an RConnection on server side.

  3. #3
    Regular Contributor
    Join Date
    Sep 2008
    Location
    India
    Posts
    126

    Question Re: Wants to implement SocketListener using Active Object ....

    Hi wizard_hu_ ,

    1. I implemetned code as per you are suggestions . It's working fine now ...

    Thanks for the help !!!

    2. I just wants to confirm one thing that, I am planing to use one more Active Object class for capturing key events along with this in the same application , And according to my understanding there should not be any problem to do so ..... will like to specify any special care which one must take in to account for doing so ?

    Thanks and Regards ,
    Kranti

  4. #4
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,175

    Re: Wants to implement SocketListener using Active Object ....

    you can have multiple activ eobject running same time, that is enable by the Active scheduler installed to your thread.

  5. #5
    Regular Contributor
    Join Date
    Sep 2008
    Location
    India
    Posts
    126

    Question Re: Wants to implement SocketListener using Active Object ....

    Hi symbianyucca,

    Thanks for information !!!

    Thanks and Regards,
    Kranti

Similar Threads

  1. An Active Object Question
    By jcyu in forum Symbian
    Replies: 2
    Last Post: 2007-12-06, 06:12
  2. Replies: 4
    Last Post: 2007-11-26, 13:41
  3. Replies: 12
    Last Post: 2007-03-16, 15:33
  4. Active Object in EXE
    By Larry101 in forum Symbian
    Replies: 21
    Last Post: 2007-01-25, 07:57
  5. Replies: 1
    Last Post: 2002-08-28, 09:12

Posting Permissions

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