다음을 통해 공유


DatagramSocket.Connect Method

Definition

Overloads

Connect(SocketAddress)

Connects this socket to a remote socket address (IP address + port number).

Connect(InetAddress, Int32)

Connects the socket to a remote address for this socket.

Connect(SocketAddress)

Connects this socket to a remote socket address (IP address + port number).

[Android.Runtime.Register("connect", "(Ljava/net/SocketAddress;)V", "GetConnect_Ljava_net_SocketAddress_Handler")]
public virtual void Connect (Java.Net.SocketAddress? addr);
[<Android.Runtime.Register("connect", "(Ljava/net/SocketAddress;)V", "GetConnect_Ljava_net_SocketAddress_Handler")>]
abstract member Connect : Java.Net.SocketAddress -> unit
override this.Connect : Java.Net.SocketAddress -> unit

Parameters

addr
SocketAddress

The remote address.

Attributes

Exceptions

if an error occurs.

Remarks

Connects this socket to a remote socket address (IP address + port number).

If given an InetSocketAddress InetSocketAddress, this method behaves as if invoking #connect(InetAddress,int) connect(InetAddress,int) with the given socket addresses IP address and port number.

Added in 1.4.

Java documentation for java.net.DatagramSocket.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

Connect(InetAddress, Int32)

Connects the socket to a remote address for this socket.

[Android.Runtime.Register("connect", "(Ljava/net/InetAddress;I)V", "GetConnect_Ljava_net_InetAddress_IHandler")]
public virtual void Connect (Java.Net.InetAddress? address, int port);
[<Android.Runtime.Register("connect", "(Ljava/net/InetAddress;I)V", "GetConnect_Ljava_net_InetAddress_IHandler")>]
abstract member Connect : Java.Net.InetAddress * int -> unit
override this.Connect : Java.Net.InetAddress * int -> unit

Parameters

address
InetAddress

the remote address for the socket

port
Int32

the remote port for the socket.

Attributes

Remarks

Connects the socket to a remote address for this socket. When a socket is connected to a remote address, packets may only be sent to or received from that address. By default a datagram socket is not connected.

If the remote destination to which the socket is connected does not exist, or is otherwise unreachable, and if an ICMP destination unreachable packet has been received for that address, then a subsequent call to send or receive may throw a PortUnreachableException. Note, there is no guarantee that the exception will be thrown.

If a security manager has been installed then it is invoked to check access to the remote address. Specifically, if the given address is a InetAddress#isMulticastAddress multicast address, the security manager's java.lang.SecurityManager#checkMulticast(InetAddress) checkMulticast method is invoked with the given address. Otherwise, the security manager's java.lang.SecurityManager#checkConnect(String,int) checkConnect and java.lang.SecurityManager#checkAccept checkAccept methods are invoked, with the given address and port, to verify that datagrams are permitted to be sent and received respectively.

When a socket is connected, #receive receive and #send send<b>will not perform any security checks</b> on incoming and outgoing packets, other than matching the packet's and the socket's address and port. On a send operation, if the packet's address is set and the packet's address and the socket's address do not match, an IllegalArgumentException will be thrown. A socket connected to a multicast address may only be used to send packets.

Java documentation for java.net.DatagramSocket.connect(java.net.InetAddress, int).

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