Reputation: 6227
Is that just impossible in Java? The DatagramSocket.bind method has to take either NULL or a IP:PORT. You cannot just pass an IP describing the NIC and let the PORT be chosen automatically. Kind of does not make sense unless I am missing something.
Upvotes: 4
Views: 3021
Reputation: 310980
Just specify a port number of zero, or omit it as suggested by Mike Q. In both cases the system will allocate a port for you.
Upvotes: 1
Reputation: 23229
Use the default constructor of DatagramSocket
. This will bind to any port. You don't have to use the bind method.
Upvotes: 0