Udostępnij za pośrednictwem


SocketChannel.Connect(SocketAddress) Method

Definition

Connects this channel's socket.

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

Parameters

remote
SocketAddress

The remote address to which this channel is to be connected

Returns

true if a connection was established, false if this channel is in non-blocking mode and the connection operation is in progress

Attributes

Exceptions

if the channel is already connected.

a non-blocking connecting operation is already executing on this channel.

if this channel is closed.

if this channel is closed by another thread while this method is executing.

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

if the address is not resolved.

if the address type is not supported.

if an I/O error occurs.

Remarks

Connects this channel's socket.

If this channel is in non-blocking mode then an invocation of this method initiates a non-blocking connection operation. If the connection is established immediately, as can happen with a local connection, then this method returns true. Otherwise this method returns false and the connection operation must later be completed by invoking the #finishConnect finishConnect method.

If this channel is in blocking mode then an invocation of this method will block until the connection is established or an I/O error occurs.

This method performs exactly the same security checks as the java.net.Socket class. That is, if a security manager has been installed then this method verifies that its java.lang.SecurityManager#checkConnect checkConnect method permits connecting to the address and port number of the given remote endpoint.

This method may be invoked at any time. If a read or write operation upon this channel is invoked while an invocation of this method is in progress then that operation will first block until this invocation is complete. If a connection attempt is initiated but fails, that is, if an invocation of this method throws a checked exception, then the channel will be closed.

Java documentation for java.nio.channels.SocketChannel.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