×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    20

    Problem with UDP socket receiving end!!

    Hi,
    I am having a problem with UDP sockets. I have a Client app and a server app and both are using UDP sockets for communicating with each other. The Client app is able to send the data (control is coming to RunL()) but the server is just not able to receive any data. I am doing my testing using 2 emulators running on 2 different machines on the LAN. Both emulators have their own IP Address. I have attached the code snippet below of both my client and my server. Pls help me!

    Server: running on 10.203.224.249, port: 5061
    ===================================
    iSocket.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp);

    const TUint32 KInetAddr = INET_ADDR(10,203,224,249);
    iLocalAddr.SetAddress(KInetAddr);
    iLocalAddr.SetPort(5061);
    iLocalAddr.SetFamily(KProtocolInetUdp);

    iSocket.Bind(iLocalAddr); //successful till here

    //Once bind is successful, i start my reader AO which does the following:
    TInetAddr lAddress;
    iSocket.RecvFrom(iBuffer, lAddress, 0, iStatus);
    SetActive(); //Control never reaches RunL() of this AO


    Client: running on 10.203.224.250, port: 5060
    ===================================
    iSocket.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp);

    const TUint32 KInetAddr = INET_ADDR(10,203,224,250);
    iLocalAddr.SetAddress(KInetAddr);
    iLocalAddr.SetPort(5060);
    iLocalAddr.SetFamily(KProtocolInetUdp);

    iSocket.Bind(iLocalAddr); //successful till here

    //Once bind is successful, i start my writer AO which does the following:
    const TUint32 KInetAddr = INET_ADDR(10,203,224,249);

    iRemoteAddress.SetAddress(KInetAddr);
    iRemoteAddress.SetPort(5061);
    iRemoteAddress.SetFamily(KProtocolInetUdp);

    iSocket.SendTo(iWriteBuffer, iRemoteAddress, 0, iStatus);
    iTimer->After( iTimeOut );
    SetActive();
    //Control reaches the RunL() of this AO, which means that data was successfully sent across.

    Looks like client sending is successful but data does not reach the server. Is there anything wrong with the code above? I am using active objects for reading and writing as described in the socket example of SDK. I am using version 8.0a.
    Kindly help.

    Rgds,
    Lakshmi

  2. #2
    Registered User
    Join Date
    May 2005
    Posts
    22

    Re: Problem with UDP socket receiving end!!

    There's at least couple of things which look a bit peculiar:

    -You don't have to call TInetAddr::SetFamily, family is already set on constuction phase of TInetAddr to be KAfInet (TCP/IP). Not sure though whether setting it to KProtocolInetUdp causes any harm.

    - lAddress you provide for method

    iSocket.RecvFrom(iBuffer, lAddress, 0, iStatus);

    should remain in scope until the asychronous receiving request completes (e.g. make it member variable of your receiving AO class). It will be filled with source address of received UDP packet after the request has completed.

    -You should do some return value error checking, like:

    User::LeaveIfError( iSocket.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp) );

    User::LeaveIfError( iSocket.Bind(iLocalAddr) );

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    20

    Unhappy Re: Problem with UDP socket receiving end!!

    Hi,
    Pls look at the points below:

    - If i dont call iLocalAddr.SetFamily(KProtocolInetUdp), Bind() is failing.

    - I had already tried with making lAddress as a data member of the receiving AO. Then the call was
    iSocket.RecvFrom(iBuffer, iAddress, 0, iStatus);
    But this was also failing...

    - I am doing error checks at every stage. I did not put it in my initial post just to make the code look simpler..

    Can someone pls help me? I am stuck at this stage..

    Rgds

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    6

    Re: Problem with UDP socket receiving end!!

    Watch out when you're using port numbers set like this.

    5060 is reserved for SIP, and if a SIP server is running on your device (or emulator), it will either (a) intercept the datagrams before you get them, or (b) not let you bind (which is what's happening when you don't specify UDP I think).

    Try a different port number.

    Search google for IANA port numbers for info on ports.

    If you're using SIP, and are writing your own SIP Server, make sure no others are running when yours is (though it's bad practice to murder core servers).

    Does this help?

    Regards,
    -Bob Andrews

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    20

    Re: Problem with UDP socket receiving end!!

    Hi,
    I dont have any SIP server running on 5060/5061. Anyways, i changed the port number and tried. But it is still not working..

    I tried to Bind in the following manner and Bind was successful:

    iLocalAddr.SetPort( 7080 );
    iLocalAddr.SetAddress( KInetAddrAny );
    iLocalAddr.SetFamily( KAfInet );

    lResult = iSocket.Bind(iLocalAddr);

    //Bind is successful as lResult is KErrNone

    So looks like iLocalAddr.SetFamily(KProtocolInetUdp) is not making a difference.

    Can someone pls help me out?

    Thx,
    Lakshmi

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    6

    Re: Problem with UDP socket receiving end!!

    What's the value of iStatus when your writer's RunL is called?

  7. #7
    Registered User
    Join Date
    Sep 2005
    Posts
    20

    Re: Problem with UDP socket receiving end!!

    Hi,
    Thx for the response. The iStatus value when RunL() of writer AO of client is called is 0 (KErrNone)

    Rgds
    PS: Could some Nokia expert pls speak up? I am clueless

  8. #8
    Registered User
    Join Date
    May 2005
    Posts
    22

    Re: Problem with UDP socket receiving end!!

    Have you checked whether the UDP packet is arriving to the receiving end PC? You can use for example Ethereal for checking this.

    If you can see UDP packet which matches with your emulators' addresses as source and destination addresses of the packet but still don't receive it on your emulator, there could be some sort of problem in your emulator network configuration...

  9. #9
    Regular Contributor
    Join Date
    Jun 2005
    Location
    Philippines
    Posts
    163

    Smile Re: Problem with UDP socket receiving end!!

    I think I read somewhere that you cannot get your own IP unless you make a connection somewhere first. If this is applicable to TCP connections then it seems to also be applicable to UDP packets. Before you do a Bind, try to do the ff:

    1. Attempt to resolve www.google.com IP address
    2. Within the RunL when the IP address was successfully retrieved, initiate a tcp connection function to google
    3. Right after that function but still within the same case statement in RunL, do a UDPSocket.Bind()

    You do not need to successfully finish the connection. There is something in the process of connecting that enables you do TCP listening and to do UDP receiving. You should be able to receive UDP messages after #3 above has successfully executed without any errors. Please post if this solves your problem.

  10. #10
    Regular Contributor
    Join Date
    Jun 2005
    Location
    Philippines
    Posts
    163

    Smile Re: Problem with UDP socket receiving end!!

    Hello,

    I just want to do a followup on this and post what I did. I learned something new in the process. It seems that you do not need to connect to an external website. You just need to do an operation like host resolving which requires an internet connection. It seems that the phone needs to make some sort of "connection" to the outside world before you can receive messages or resolve your local IP address. I may be wrong though so please post if this does not work for you.

    1. Resolve www.google.com.ph
    _LIT( KDefaultGoogleAddress, "www.google.com.ph" );
    // Initiate DNS
    User::LeaveIfError( iResolver.Open( iTCPSocketServ,
    KAfInet,
    KProtocolInetTcp ) );
    // DNS request for name resolution
    iResolver.GetByName( KDefaultGoogleAddress, iNameEntry, iStatus );

    iEngineStatus = ELookingUpWebsiteIP;
    // Request time out
    iTimer->After( KTimeOut );
    SetActive();
    2. In the RunL() function I caught the ElookingUpWebsiteIP case
    case ELookingUpWebsiteIP:
    {
    iResolver.Close();
    if ( iStatus == KErrNone )
    {
    // DNS look up successful
    iNameRecord = iNameEntry();

    BindUDPToAddress( KDefaultLocalIP, iPort);
    }
    iEngineStatus = ENotConnected;
    break;
    }
    where BindUDPToAddress is defined in the same class as
    void CUDPSocketEngine::BindUDPToAddress( const TDesC& aAddr, TInt aPort )
    {
    TInetAddr local( aPort );
    if( local.Input( aAddr ) == KErrNone )
    {
    User::LeaveIfError( iUDPSocket.Bind( local ) );
    }
    }
    I noticed that sometimes the google address is not resolved within the 30sec timeout specified. I also tried doing a bind when timeout occurs altho I have not done much testing in that scenario. As long as you have successfully done a bind and you can ping your emulator's IP address from the command prompt, you should be receiving UDP packets from another client. Just make sure you have the proper address in your RecvFrom function. Aside from this, I guess I have no other advice. What I mentioned above works for me
    Last edited by RyanSantos; 2006-02-14 at 07:49.

Similar Threads

  1. j2me支持 udp socket 吗 ?
    By RongJia in forum [Archived] Other Programming Discussion 关于其他编程技术的讨论
    Replies: 5
    Last Post: 2005-09-16, 06:11
  2. Socket problem
    By defragger in forum Symbian
    Replies: 0
    Last Post: 2005-08-25, 08:16
  3. Problem opening Server Socket?
    By camroe in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2005-03-02, 22:27
  4. Socket Problem
    By cliges in forum Symbian
    Replies: 0
    Last Post: 2004-05-26, 11:09
  5. Problem for MVNO customers receiving operator logo
    By kep9604 in forum Digital Rights Management & Content Downloading
    Replies: 0
    Last Post: 2003-12-17, 14:53

Posting Permissions

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