Class NioTcpSocket
- java.lang.Object
-
- org.johnnei.javatorrent.network.socket.NioTcpSocket
-
- All Implemented Interfaces:
AutoCloseable,ISocket
public class NioTcpSocket extends Object implements ISocket
Default TCP Socket implementation which uses NIO as the underlying platform.
-
-
Constructor Summary
Constructors Constructor Description NioTcpSocket()Creates a new non-blocking TCP Socket.NioTcpSocket(SocketChannel channel)Creates a new Socket with an pre-exisiting channel.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Formally closes the connectionvoidconnect(InetSocketAddress endpoint)Connects the underlying Socket to the endpoint.SocketChannelgetReadableChannel()SocketChannelgetWritableChannel()booleanisClosed()Checks if the connection has been closedbooleanisConnected()booleanisInputShutdown()Checks if there will be no more data incomingbooleanisOutputShutdown()Checks if no more data can be send on this socket
-
-
-
Constructor Detail
-
NioTcpSocket
public NioTcpSocket(SocketChannel channel)
Creates a new Socket with an pre-exisiting channel. The channel must be in non-blocking mode.- Parameters:
channel- The pre-exisiting channel.- Throws:
IllegalArgumentException- When the channel is in blocking mode.
-
NioTcpSocket
public NioTcpSocket()
Creates a new non-blocking TCP Socket.
-
-
Method Detail
-
connect
public void connect(InetSocketAddress endpoint) throws IOException
Description copied from interface:ISocketConnects the underlying Socket to the endpoint. This event must happen asynchronously. To notify the socket is connected (or it failed) useSelectionKey.OP_CONNECTin combination withISocket.isConnected().- Specified by:
connectin interfaceISocket- Parameters:
endpoint- The Address to connect to- Throws:
IOException- When connection fails
-
isConnected
public boolean isConnected()
- Specified by:
isConnectedin interfaceISocket- Returns:
trueif the connection is successfully established. Otherwisefalse.
-
getReadableChannel
public SocketChannel getReadableChannel()
- Specified by:
getReadableChannelin interfaceISocket
-
getWritableChannel
public SocketChannel getWritableChannel()
- Specified by:
getWritableChannelin interfaceISocket
-
close
public void close() throws IOExceptionDescription copied from interface:ISocketFormally closes the connection- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceISocket- Throws:
IOException- When the connection could not be closed
-
isClosed
public boolean isClosed()
Description copied from interface:ISocketChecks if the connection has been closed
-
isInputShutdown
public boolean isInputShutdown()
Description copied from interface:ISocketChecks if there will be no more data incoming- Specified by:
isInputShutdownin interfaceISocket- Returns:
- true if EOF has been found
-
isOutputShutdown
public boolean isOutputShutdown()
Description copied from interface:ISocketChecks if no more data can be send on this socket- Specified by:
isOutputShutdownin interfaceISocket- Returns:
- true if EOF has been send
-
-