Semaphor
Semaphor

Reputation: 1040

Bind DatagramSocket to specific InetAddress but arbitrary port

Is it possible to bind a DatagramSocket in java to a specific InetAddress but let choose the system the port, like it is done when calling the DatagramSocket() constructor?

Upvotes: 0

Views: 68

Answers (1)

Zbynek Vyskovsky - kvr000
Zbynek Vyskovsky - kvr000

Reputation: 18855

You have to put 0 as port number to InetSocketAddress constructor. You can then get real port number by calling getLocalAddress() or getLocalPort.

Upvotes: 2

Related Questions