Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User gasparino's Avatar
    Join Date
    Jan 2009
    Posts
    2
    Hi,

    I'm implementing a UDP server/client using Active objects. The server listen at a port and send a ACK message back to the client.

    The server code is something like this:





    void CUdpServer::ConstructL(TInt aPort)
    {
    // CActiveScheduler::Add(this);
    iMessage = CMessage::NewL();
    iState = EIdle;
    iAppUi->PrintMsg(_L("server constructed"));
    applicationPort = aPort;
    }


    void
    CUdpServer::DoReceive()
    {
    TBool ret = EFalse;
    iSock.RecvFrom(iBuffer, iFrom, 0, iStatus);
    applicationPort = iFrom.Port();
    iAppUi->PrintMsg(_L("server receives data"));
    TBuf<120> temp;
    temp.Zero();
    temp.Copy(iBuffer);
    ret = iMessage->ParseMessage(temp, CMessage::ERegister);

    if(ret)
    {
    iAppUi->PrintMsg(_L("server receives registration data"));
    iState = EReceiving;
    }
    iState = EReceiving;
    SetActive();

    }
    //================================================
    void CUdpServer::DoSendConfirm()
    {
    const TUint32 KInetAddr2 = INET_ADDR(127,0,0,1);
    TInetAddr addr(KInetAddr2, applicationPort );
    iMessage->GenerateMessage(CMessage::EConfirm);
    iBuffer.Zero();
    iBuffer.Copy(iMessage->GetMessage());
    iSock.SendTo(iBuffer, addr, 0, iStatus);
    iState = EIdle;
    SetActive();
    }

    ...
    void CUdpServer::RunL()
    {
    if(iStatus.Int() == KErrNone)
    {
    if(iState == EReceiving)
    DoSendConfirm();
    else
    DoReceive();
    }

    }

    ...

    void CUdpServer::Start()
    {
    User::LeaveIfError( iServ.Connect() );
    User::LeaveIfError( iSock.Open(iServ, KAfInet, KSockDatagram, KProtocolInetUdp) );


    iSock.SetLocalPort(1000);

    iState = EIdle;
    DoReceive();

    }









    The server starts by running Start() function. When the first message arrives, it could read in and process, however, then the DoSendConfirm is never invoked.

    If the client sends another request, DoSendConfirm then runs the first time. It looks like the pending request from the first message now is running.

    Please help.

  2. #2
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Mallorca, Holiday
    Posts
    27,683
    Note that RSocket-actions are asynchronous. When you invoke RecvFrom, you are just starting a request, you can not handle its results immediately - because there will be no immediate results most of the time. So RecvFrom, SetActive, iState=xy, return.
    The rest (iFrom and iBuffer stuff) should go into RunL, which is going to be invoked when something is actually received.

  3. #3
    Registered User gasparino's Avatar
    Join Date
    Jan 2009
    Posts
    2
    Thank you. I have been stuck for the last two days.

Similar Threads

  1. Regarding UDp connection
    By symbiannil in forum Symbian C++
    Replies: 3
    Last Post: 2008-01-21, 11:05
  2. UDP and ICMP Network unreachable packet
    By arikr7 in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2007-09-05, 07:18
  3. Anybody succeded udp connection on Series40??
    By pz1974 in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2007-01-10, 21:12
  4. Race condition in UDP sockets on Nokia 6102i
    By vnagarjuna in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2006-06-21, 22:46
  5. Fragmented Udp Packets - Experts Help!!!
    By stenlik in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2005-07-22, 14:02

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved