public interface NetworkChannel extends AutoCloseable
| Modifier and Type | Method and Description |
|---|---|
void |
bind(InetSocketAddress address)
Binds the channel to an address.
|
void |
close()
Disconnects and closes the channel.
Invoking this method will have no effect if the channel is already closed. |
void |
connect(InetSocketAddress address)
Connects the channel to a remote peer.
The channel will only be able to accept traffic from that peer. |
void |
disconnect()
Disconnect the channel
|
InetSocketAddress |
getLocalAddress()
Gets the address the channel is bound to.
|
InetSocketAddress |
getRemoteAddress()
Gets the address of the remote peer this channel is connected to.
|
boolean |
isConnected()
Gets whether channel is connected or not.
|
boolean |
isOpen()
Gets whether channel is open or not.
|
boolean |
isRegistered()
Gets whether channel is registered in a Selector.
|
void |
open()
Opens the channel.
|
void |
receive()
Receives incoming data.
|
void |
register(Selector selector,
int opts)
Registers this channel into a selector for multiplexing purposes.
|
void |
send(byte[] data)
Sends data to the remote peer.
|
void |
send(byte[] data,
InetSocketAddress remotePeer)
Send data through the channel.
|
void |
send(ByteBuffer data,
InetSocketAddress remotePeer)
Send data through the channel.
|
void bind(InetSocketAddress address) throws IOException
address - the address the channel will be bounds toIOException - In case the channel is closed or could not be bound.void open()
throws IOException
IOException - If the channel is already open or if it could not be opened.void close()
close in interface AutoCloseablevoid register(Selector selector, int opts) throws ClosedChannelException
selector - The selector where the channel will be registered.The - channel valid operation keys.ClosedChannelException - If the channel is closedvoid connect(InetSocketAddress address) throws IOException
address - The address of the remote peer to connect toIOExceptionvoid disconnect()
throws IOException
IOExceptionInetSocketAddress getLocalAddress()
InetSocketAddress getRemoteAddress()
void receive()
throws IOException
IOExceptionvoid send(byte[] data)
throws IOException
data - The data to be sent.IOExceptionvoid send(byte[] data,
InetSocketAddress remotePeer)
throws IOException
data - The data to be sent.remotePeer - The address of the remote peer.IOExceptionvoid send(ByteBuffer data, InetSocketAddress remotePeer) throws IOException
data - The data to be sent.remotePeer - The address of the remote peer.IOExceptionboolean isConnected()
true if the channel is connected. Otherwise, returns false.boolean isOpen()
true if the channel is open. Otherwise, returns false.boolean isRegistered()
true if the channel is registered. Otherwise, returns false.Copyright © 2017 TeleStax, Inc.. All Rights Reserved.