chrisapotek
chrisapotek

Reputation: 6227

Is there a way to bind a DatagramSocket to any port on a specific nic or if I specify the nic I have to specify the port?

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

Answers (2)

user207421
user207421

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

Mike Q
Mike Q

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

Related Questions