Thread: dynamic binding

  1. #1
    I am free!
    Join Date
    Oct 2004

    dynamic binding

    hi, i need help with my homework. i have a sender and a receiver (both uses UDP). my teacher wants us to make the receiver 'dynamically' bind to a port and then 'announce' that port so that the sender would know where to send (we're supposed to use bind() and getsockname() to achieve this). my questions: what exactly is meant by dynamic binding? and how do i use bind() and getsockname() for 'dynamic binding.' i read the man pages for these functions but none mentions 'dynamic binding'
    thanks in advance.

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    IIRC, If your port is set to 0 a dynamic one will be bound, it can then be retrieved again with getsockname()

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    By specifying the address INADDR_ANY and the port 0, rather than an explicit address and/or port, you can instruct the socket provider to automatically select a source address and port. I believe this is what your teacher is referring to when he/she talks of "dynamic binding".

    From the sounds of your description I expect the teacher wants something like the following:

    1. Call bind() to "dynamically bind" to a port/address.
    2. Call getsockname to see which port address the socket has been bound to.
    3. Announce that information.

    I'm prepared to give your instructor the benefit of the doubt for requesting you use bind(), but this can be done simply without bind().

    1. Use sendto() to send a one byte packet to the peer. This causes an implicit dynamic bind.
    2. Use recvfrom() on the peer. This will return the remote address/port.

    On a side note, the nix documentation is often very brief. I see the man page for bind() does not mention the use of INADDR_ANY, etc. You can sometimes pick up extra tips on the msdn page for a socket function, although some aspects do differ.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. boost::shared_ptr and dynamic binding
    By Mario F. in forum C++ Programming
    Replies: 2
    Last Post: 07-24-2006, 03:50 PM
  2. Dynamic binding
    By Mario F. in forum C++ Programming
    Replies: 5
    Last Post: 07-09-2006, 04:37 PM
  3. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 09:01 AM
  4. dynamic or static binding
    By noob2c in forum C++ Programming
    Replies: 1
    Last Post: 08-06-2003, 01:43 PM
  5. Static Binding & Dynamic Binding :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 12-31-2001, 08:51 PM