UDP client needs bind() ??

This is a discussion on UDP client needs bind() ?? within the Networking/Device Communication forums, part of the General Programming Boards category; I've never really gave UDP sockets much thought by some once told me that UDP client needs to be bind()ed ...

  1. #1
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768

    UDP client needs bind() ??

    I've never really gave UDP sockets much thought by some once told me that UDP client needs to be bind()ed to a port before the application will be able to send a datagram packet, is it true, or could it be some weird windows implementation bug, since the MSDN says nothing like that about UDP clients...


    Thank you.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    No, you don't need to bind a socket before using sendto. If the socket is not already bound, sendto will perform an implicit bind (for TCP sockets this implicit bind is done on connect). It is generally recommended to let Windows do an implicit bind if one doesn't need a specific local port. This avoids the issue of conflicts with other programs. An explicit bind will also activate the Windows firewall.
    Last edited by anonytmouse; 11-08-2005 at 04:06 PM.

  3. #3
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    Quote Originally Posted by anonytmouse
    An explicit bind will also activate the Windows firewall.
    You mean when I use bind() it activates the windows FW? why? is there a way to avoid it?
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,255
    why?
    Because it's the firewall's job to block traffic. If a program explicitly binds to a specific port, then it is essentially acting as a server on that port, and thus it introduces a security risk.

    is there a way to avoid it?
    The only way to avoid it (short of disabling the firewall) is to only bind implicitly. That is, don't call the bind() function, and let Windows handle it for you.
    Last edited by bithub; 11-11-2005 at 08:38 PM.

  5. #5
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    ... (short of disabling the firewall) ...
    Oh, sorry miss understood the "activate FW"
    I thought that Windows is capable of starting the FW even after it was disabled.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can I bind a UDP socket to a port, but send to any other port?
    By trillianjedi in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-25-2009, 04:27 PM
  2. Error in creating socket in a client (UDP)
    By ferenczi in forum Networking/Device Communication
    Replies: 2
    Last Post: 11-27-2008, 11:11 AM
  3. Using select() for client UDP
    By jazzman83 in forum C Programming
    Replies: 2
    Last Post: 04-03-2007, 06:31 AM
  4. UDP Server -> Displaying Client Information
    By Jedimark in forum Networking/Device Communication
    Replies: 6
    Last Post: 12-05-2003, 12:57 PM
  5. udp client
    By rotis23 in forum Linux Programming
    Replies: 3
    Last Post: 11-08-2002, 08:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21