# NetworkChannel

public interface **NetworkChannel** implements [Channel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Channel.html)

|---|---|---|
| Known Indirect Subclasses [AsynchronousServerSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousServerSocketChannel.html), [AsynchronousSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html), [DatagramChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html), [MulticastChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MulticastChannel.html), [ServerSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ServerSocketChannel.html), [SocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SocketChannel.html) |---|---| | [AsynchronousServerSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousServerSocketChannel.html) | An asynchronous channel for stream-oriented listening sockets. | | [AsynchronousSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html) | An asynchronous channel for stream-oriented connecting sockets. | | [DatagramChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html) | A selectable channel for datagram-oriented sockets. | | [MulticastChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MulticastChannel.html) | A network channel that supports Internet Protocol (IP) multicasting. | | [ServerSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ServerSocketChannel.html) | A selectable channel for stream-oriented listening sockets. | | [SocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SocketChannel.html) | A selectable channel for stream-oriented connecting sockets. | |||

A channel to a network socket.

A channel that implements this interface is a channel to a network
socket. The `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#bind(java.net.SocketAddress)` method is used to bind the
socket to a local `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html`, the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#getLocalAddress()` method returns the address that the socket is bound to, and
the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#setOption(java.net.SocketOption<T>,%20T)` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#getOption(java.net.SocketOption<T>)` methods are used to set and query socket
options. An implementation of this interface should specify the socket options
that it supports.

The `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#bind(java.net.SocketAddress)` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#setOption(java.net.SocketOption<T>,%20T)` methods that do
not otherwise have a value to return are specified to return the network
channel upon which they are invoked. This allows method invocations to be
chained. Implementations of this interface should specialize the return type
so that method invocations on the implementation class can be chained.

### Public Method Summary

|---|---|
| abstract [NetworkChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html) | [bind](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#bind(java.net.SocketAddress))([SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) local) Binds the channel's socket to a local address. |
| abstract [SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) | [getLocalAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#getLocalAddress())() Returns the socket address that this channel's socket is bound to. |
| abstract \<T\> T | [getOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#getOption(java.net.SocketOption<T>))([SocketOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOption.html)\<T\> name) Returns the value of a socket option. |
| abstract \<T\> [NetworkChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html) | [setOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#setOption(java.net.SocketOption<T>,%20T))([SocketOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOption.html)\<T\> name, T value) Sets the value of a socket option. |
| abstract [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<[SocketOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOption.html)\<?\>\> | [supportedOptions](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#supportedOptions())() Returns a set of the socket options supported by this channel. |

### Inherited Method Summary

From interface [java.nio.channels.Channel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Channel.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Channel.html#close())() Closes this channel. |
| abstract boolean | [isOpen](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Channel.html#isOpen())() Tells whether or not this channel is open. |

From interface [java.io.Closeable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html#close())() Closes this stream and releases any system resources associated with it. |

From interface [java.lang.AutoCloseable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/AutoCloseable.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/AutoCloseable.html#close())() Closes this resource, relinquishing any underlying resources. |

## Public Methods

#### public abstract [NetworkChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html)
**bind**
([SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) local)

Binds the channel's socket to a local address.

This method is used to establish an association between the socket and
a local address. Once an association is established then the socket remains
bound until the channel is closed. If the `local` parameter has the
value `null` then the socket will be bound to an address that is
assigned automatically.

##### Parameters

| local | The address to bind the socket, or `null` to bind the socket to an automatically assigned socket address |
|---|---|

##### Returns

- This channel

##### Throws

| [AlreadyBoundException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AlreadyBoundException.html) | If the socket is already bound |
| [UnsupportedAddressTypeException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/UnsupportedAddressTypeException.html) | If the type of the given address is not supported |
| [ClosedChannelException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedChannelException.html) | If the channel is closed |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If some other I/O error occurs |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | If a security manager is installed and it denies an unspecified permission. An implementation of this interface should specify any required permissions. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#getLocalAddress()`

#### public abstract [SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html)
**getLocalAddress**
()

Returns the socket address that this channel's socket is bound to.

Where the channel is `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#bind(java.net.SocketAddress)` to an Internet Protocol
socket address then the return value from this method is of type `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html`.

##### Returns

- The socket address that the socket is bound to, or `null` if the channel's socket is not bound

##### Throws

| [ClosedChannelException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedChannelException.html) | If the channel is closed |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If an I/O error occurs |
|---|---|

#### public abstract T
**getOption**
([SocketOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOption.html)\<T\> name)

Returns the value of a socket option.

##### Parameters

| name | The socket option |
|---|---|

##### Returns

- The value of the socket option. A value of `null` may be a valid value for some socket options.

##### Throws

| [UnsupportedOperationException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/UnsupportedOperationException.html) | If the socket option is not supported by this channel |
| [ClosedChannelException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedChannelException.html) | If this channel is closed |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If an I/O error occurs |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/StandardSocketOptions.html`

#### public abstract [NetworkChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html)
**setOption**
([SocketOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOption.html)\<T\> name, T value)

Sets the value of a socket option.

##### Parameters

| name | The socket option |
| value | The value of the socket option. A value of `null` may be a valid value for some socket options. |
|---|---|

##### Returns

- This channel

##### Throws

| [UnsupportedOperationException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/UnsupportedOperationException.html) | If the socket option is not supported by this channel |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | If the value is not a valid value for this socket option |
| [ClosedChannelException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedChannelException.html) | If this channel is closed |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If an I/O error occurs |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/StandardSocketOptions.html`

#### public abstract [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<[SocketOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOption.html)\<?\>\>
**supportedOptions**
()

Returns a set of the socket options supported by this channel.

This method will continue to return the set of options even after the
channel has been closed.

##### Returns

- A set of the socket options supported by this channel