Three methods of DatagramChannel, connect, send, and receive, may implicitly bind the channel, if not already bound. All three method descriptions contain the following statement in their specification:
"If this channel's socket is not bound then this method will first cause the socket to be bound to an address that is assigned automatically, as if invoking the bind method with a parameter of null."
In the DatagramChannel implementation:
1) both send and receive effectively invoke the bind method as described. Bind may fail if the caller does not have the required permission ( the permission is granted by default, but there is still a security manager checkListen call, and the default permissions can be overridden ).
2) the connect method does not invoke bind. It instead relies on the native connect in the kernel to perform the implicit bind.
"If this channel's socket is not bound then this method will first cause the socket to be bound to an address that is assigned automatically, as if invoking the bind method with a parameter of null."
In the DatagramChannel implementation:
1) both send and receive effectively invoke the bind method as described. Bind may fail if the caller does not have the required permission ( the permission is granted by default, but there is still a security manager checkListen call, and the default permissions can be overridden ).
2) the connect method does not invoke bind. It instead relies on the native connect in the kernel to perform the implicit bind.
- blocks
-
JDK-8230211 Prepare DatagramSocket for alternative DatagramSocketImpl
- Resolved
- csr for
-
JDK-8232385 (dc) Clarify implicit bind behavior of DatagramChannel
- Closed