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
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 Socket
class. That is, if a security manager has been
installed then this method verifies that its 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.
Returns:
true if a connection was established,
false if this channel is in non-blocking mode
and the connection operation is in progress
Parameters:
-
remote - The remote address to which this channel is to be connected
Throws:
-
AlreadyConnectedException - If this channel is already connected
-
ConnectionPendingException - If a non-blocking connection operation is already in progress
on this channel
-
ClosedChannelException - If this channel is closed
-
AsynchronousCloseException - If another thread closes this channel
while the connect operation is in progress
-
ClosedByInterruptException - If another thread interrupts the current thread
while the connect operation is in progress, thereby
closing the channel and setting the current thread's
interrupt status
-
UnresolvedAddressException - If the given remote address is not fully resolved
-
UnsupportedAddressTypeException - If the type of the given remote address is not supported
-
SecurityException - If a security manager has been installed
and it does not permit access to the given remote endpoint
-
IOException - If some other I/O error occurs