×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    42

    Problem regarding binding of Socket..

    hi
    my code is not being able to bind socket, neither my code is leaving anywhere.
    i am giving my piece of code, if anybody can suggest that what could be possible reasons to this problem....

    i want to make clear that i am running this code on emultor n i have issued Open(socketserversession,KAfInet,KSockDatagram,KUnspecified); prior to CSocket::Bind() without any RConnection instance.
    N also iSocket is member variable of CSocket class.

    TInt CSocket::Bind(TUint aLocalPort)
    {
    TInetAddr anAddr(aLocalPort);
    const TUint32 KInetAddr = INET_ADDR(127,0,0,1);
    anAddr.SetAddress(KInetAddr);
    User::LeaveIfError(iSocket.Bind(anAddr));

    TInetAddr addr;

    iSocket.LocalName(addr);
    //At this point i am checking whether socket is binded to correct address or not.

    if(! addr.Match(anAddr))
    {
    //control of the program is getting inside this if statement.
    }

    iStateOfSocket=ESocketBinded;//Socket state changed.
    return 1;
    }

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,734

    Re: Problem regarding binding of Socket..

    And what gets in addr?

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    42

    Re: Problem regarding binding of Socket..

    Quote Originally Posted by wizard_hu_
    And what gets in addr?
    Hi,
    when i am printing addr.Port() , i am getting value much large like 61357023.
    N aLocalPort is containing value 7.
    i don't know why this is happening, bcoz using debugger code is neither leaving nothing unusual is happening.
    i am sure of this that socket is not getting binded on the port specified by me (port no. 7) bcoz when i again issue bind on the same port no 7 then again bind is getting successfull.
    Rgds,
    Amit.

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,734

    Re: Problem regarding binding of Socket..

    I have tried it, and it works for me (with KProtocolInetUdp instead of "KUnspecified" which does not exist).

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    42

    Re: Problem regarding binding of Socket..

    Quote Originally Posted by wizard_hu_
    I have tried it, and it works for me (with KProtocolInetUdp instead of "KUnspecified" which does not exist).
    Hi,
    Thanx Buddy, i have solved this problem with ur help, by replacing KUnspecified with KProtocolInetUdp, i am being able to bind the socket.
    Thanx for it.

    But now i am stucking further, i have spent lot of time in finding where the problem is but i am not getting the clue.
    Actually what happening is, after binding socket i am issuing SendTo(), which is also not leaving the code nothing unusual is happening, but it is not sending data to my specified port, i have checked it through Ethereal.
    i give u piece of code, could u plz have a look at it..??
    This SendTo() is also a member of CUdpSocket(which is inherited from CSocket) class which is internally calling RSocket's SendTo().
    Also i am implementing SendTo() as Synchronous(Not Asynchronous).

    TInt CUdpSocket::SendTo(const TDesC& aDestinationAddrRef,
    TUint aDestinationPort,
    const TDesC8& aDataRef)
    {
    TRequestStatus Status;
    TInetAddr addr;
    //const TUint32 KInetAddr = INET_ADDR(127,0,0,1);
    //addr.SetAddress(KInetAddr);
    addr.SetPort(aDestinationPort);//aDestinationPort is containing value
    //7, no problem with that
    addr.Input(_L("127.0.0.1"));
    TSockXfrLength aLen;

    iSocket.SendTo(aDataRef,addr,0,Status,aLen);
    User::WaitForRequest(Status);
    if (Status != KErrNone)
    User::Leave(Status.Int());
    return aLen.operator();
    }

    when i am using debugger to get the returned value from this function i.e aLen it is giving me 0 as return value from this CUdpSocket::SendTo().

    Regards,
    Amit.

  6. #6
    Registered User
    Join Date
    Apr 2005
    Location
    Barcelona
    Posts
    1,678

    Re: Problem regarding binding of Socket..

    Some quick notes:
    1. You shouldn't use the loopback ip, use the ip assigned to the (PC) network interface.
    2. Don't rely on the len parameter. I recall having some issues with it in the past

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    42

    Re: Problem regarding binding of Socket..

    Quote Originally Posted by PushL
    Some quick notes:
    1. You shouldn't use the loopback ip, use the ip assigned to the (PC) network interface.
    2. Don't rely on the len parameter. I recall having some issues with it in the past
    Hi,
    I am testing my appn on emulator.
    so i am running two exes in different emulators on the same PC, then why can't i use the loopback IP in binding..???
    I have also tried with the IP assigned to my PC, i have tried bind on that IP but i don't know why when bind() gets encounterd then program leaves with leave code -1(means specified object not found), i don't know why????

    Amit.

  8. #8
    Registered User
    Join Date
    Apr 2005
    Location
    Barcelona
    Posts
    1,678

    Re: Problem regarding binding of Socket..

    Datagrams sent to the loopback address don't go to the data link layer, so they don't get to the network interface. Read some tcp/ip basics for further info about this topic.
    bind() should work if used correctly.. search this forum for snippets.

Similar Threads

  1. problem in persistant socket connection
    By poms4symbian in forum Browsing and Mark-ups
    Replies: 0
    Last Post: 2006-01-03, 13:23
  2. problem with socket write
    By srkreddy999 in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2005-11-02, 14:33
  3. Socket problem
    By max2k5 in forum Symbian
    Replies: 5
    Last Post: 2005-08-16, 15:11
  4. Socket problem
    By Smeetesh Ooka in forum Mobile Java General
    Replies: 1
    Last Post: 2004-10-07, 21:20
  5. TCP/IP socket connection problem
    By ArunP in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2002-09-19, 10:09

Posting Permissions

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