Share via


DatagramChannel.Connect(SocketAddress) Method

Definition

Connects this channel's socket.

[Android.Runtime.Register("connect", "(Ljava/net/SocketAddress;)Ljava/nio/channels/DatagramChannel;", "GetConnect_Ljava_net_SocketAddress_Handler")]
public abstract Java.Nio.Channels.DatagramChannel? Connect (Java.Net.SocketAddress? remote);
[<Android.Runtime.Register("connect", "(Ljava/net/SocketAddress;)Ljava/nio/channels/DatagramChannel;", "GetConnect_Ljava_net_SocketAddress_Handler")>]
abstract member Connect : Java.Net.SocketAddress -> Java.Nio.Channels.DatagramChannel

Parameters

remote
SocketAddress

The remote address to which this channel is to be connected

Returns

This datagram channel

Attributes

Exceptions

if the channel is already closed.

if the channel is closed by another thread while this method is in operation.

if another thread interrupts the calling thread while the operation is in progress. The calling thread will have the interrupt state set and the channel will be closed.

if some other I/O error occurs.

Remarks

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. A datagram socket remains connected until it is explicitly disconnected or until it is closed.

This method performs exactly the same security checks as the java.net.DatagramSocket#connect connect method of the java.net.DatagramSocket class. That is, if a security manager has been installed then this method verifies that its java.lang.SecurityManager#checkAccept checkAccept and java.lang.SecurityManager#checkConnect checkConnect methods permit datagrams to be received from and sent to, respectively, the given remote address.

This method may be invoked at any time. It will not have any effect on read or write operations that are already in progress at the moment that it is invoked. 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 bind method with a parameter of null.

Java documentation for java.nio.channels.DatagramChannel.connect(java.net.SocketAddress).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to