Connects this channel's socket.
The channel's socket is configured so that it only receives datagrams from, and sends datagrams to, the given remote peer address. Once connected, datagrams may not be received from or sent to any other address. Datagrams in the channel's socket receive buffer , which have not been received before invoking this method, may be discarded. The channel's socket remains connected until it is explicitly disconnected or until it is closed.
This method performs exactly the same security checks as the connect
method of the DatagramSocket
class. That is, if a security manager has been installed then this method verifies that its checkAccept
and checkConnect
methods permit datagrams to be received from and sent to, respectively, the given remote address. Once connected, no further security checks are performed for datagrams received from, or sent to, the given remote address. Care should be taken to ensure that a connected datagram channel is not shared with untrusted code.
This method may be invoked at any time. If another thread has already initiated a read or write operation upon this channel, then an invocation of this method will block until any such operation is complete. 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
.