×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    2

    Need help with UDP server/client

    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
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,671

    Re: Need help with UDP server/client

    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
    Join Date
    Jan 2009
    Posts
    2

    Re: Need help with UDP server/client

    Thank you. I have been stuck for the last two days.

Similar Threads

  1. Regarding UDp connection
    By symbiannil in forum Symbian
    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
  •  
×