I can initialize a DatagramSocket with a zero arg constructor, and the OS will choose the port number for the socket
DatagramSocket socket = new DatagramSocket();
But when I call getPort()
on the socket, the result returned is -1
So I'm just wondering, is it even possible to know the port number assigned to the socket by the OS?
You can get it via getLocalPort()
.
Rather a trivial question.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.