# DatagramChannel

public abstract class **DatagramChannel** extends [AbstractSelectableChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractSelectableChannel.html)  
implements [ByteChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ByteChannel.html) [ScatteringByteChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ScatteringByteChannel.html) [GatheringByteChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/GatheringByteChannel.html) [MulticastChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MulticastChannel.html) A selectable channel for datagram-oriented sockets.

A datagram channel is created by invoking one of the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#open()` methods
of this class. It is not possible to create a channel for an arbitrary,
pre-existing datagram socket. A newly-created datagram channel is open but not
connected. A datagram channel need not be connected in order for the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#send(java.nio.ByteBuffer,%20java.net.SocketAddress)` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#receive(java.nio.ByteBuffer)` methods to be used. A datagram channel may be
connected, by invoking its `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#connect(java.net.SocketAddress)` method, in order to
avoid the overhead of the security checks are otherwise performed as part of
every send and receive operation. A datagram channel must be connected in
order to use the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#read(java.nio.ByteBuffer)` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#write(java.nio.ByteBuffer)` methods, since those methods do not
accept or return socket addresses.

Once connected, a datagram channel remains connected until it is
disconnected or closed. Whether or not a datagram channel is connected may
be determined by invoking its `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#isConnected()` method.

Socket options are configured using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#setOption(java.net.SocketOption<T>,%20T)` method. A datagram channel to an Internet Protocol socket supports
the following options:
>
> | Option Name | Description |
> |---|---|
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/StandardSocketOptions.html#SO_SNDBUF` | The size of the socket send buffer |
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/StandardSocketOptions.html#SO_RCVBUF` | The size of the socket receive buffer |
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/StandardSocketOptions.html#SO_REUSEADDR` | Re-use address |
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/StandardSocketOptions.html#SO_BROADCAST` | Allow transmission of broadcast datagrams |
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/StandardSocketOptions.html#IP_TOS` | The Type of Service (ToS) octet in the Internet Protocol (IP) header |
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/StandardSocketOptions.html#IP_MULTICAST_IF` | The network interface for Internet Protocol (IP) multicast datagrams |
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/StandardSocketOptions.html#IP_MULTICAST_TTL` | The *time-to-live* for Internet Protocol (IP) multicast datagrams |
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/StandardSocketOptions.html#IP_MULTICAST_LOOP` | Loopback for Internet Protocol (IP) multicast datagrams |

Additional (implementation specific) options may also be supported.

Datagram channels are safe for use by multiple concurrent threads. They
support concurrent reading and writing, though at most one thread may be
reading and at most one thread may be writing at any given time.

<br />

### Protected Constructor Summary

|---|---|
|   | [DatagramChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#DatagramChannel(java.nio.channels.spi.SelectorProvider))([SelectorProvider](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/SelectorProvider.html) provider) Initializes a new instance of this class. |

### Public Method Summary

|---|---|
| abstract [DatagramChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html) | [bind](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.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 [DatagramChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html) | [connect](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#connect(java.net.SocketAddress))([SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) remote) Connects this channel's socket. |
| abstract [DatagramChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html) | [disconnect](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#disconnect())() Disconnects this channel's socket. |
| 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/DatagramChannel.html#getLocalAddress())() Returns the socket address that this channel's socket is bound to. If there is a security manager set, its `checkConnect` method is called with the local address and `-1` as its arguments to see if the operation is allowed. |
| abstract [SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) | [getRemoteAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#getRemoteAddress())() Returns the remote address to which this channel's socket is connected. |
| abstract boolean | [isConnected](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#isConnected())() Tells whether or not this channel's socket is connected. |
| static [DatagramChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html) | [open](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#open())() Opens a datagram channel. |
| static [DatagramChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html) | [open](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#open(java.net.ProtocolFamily))([ProtocolFamily](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProtocolFamily.html) family) Opens a datagram channel. |
| abstract long | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#read(java.nio.ByteBuffer[],%20int,%20int))([ByteBuffer\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dsts, int offset, int length) Reads a datagram from this channel. |
| abstract int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#read(java.nio.ByteBuffer))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dst) Reads a datagram from this channel. |
| final long | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#read(java.nio.ByteBuffer[]))([ByteBuffer\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dsts) Reads a datagram from this channel. |
| abstract [SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) | [receive](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#receive(java.nio.ByteBuffer))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dst) Receives a datagram via this channel. |
| abstract int | [send](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#send(java.nio.ByteBuffer,%20java.net.SocketAddress))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) src, [SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) target) Sends a datagram via this channel. |
| abstract \<T\> [DatagramChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html) | [setOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.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 [DatagramSocket](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocket.html) | [socket](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#socket())() Retrieves a datagram socket associated with this channel. |
| final int | [validOps](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#validOps())() Returns an operation set identifying this channel's supported operations. |
| abstract int | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#write(java.nio.ByteBuffer))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) src) Writes a datagram to this channel. |
| final long | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#write(java.nio.ByteBuffer[]))([ByteBuffer\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) srcs) Writes a datagram to this channel. |
| abstract long | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#write(java.nio.ByteBuffer[],%20int,%20int))([ByteBuffer\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) srcs, int offset, int length) Writes a datagram to this channel. |

### Inherited Method Summary

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

|---|---|
| final [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [blockingLock](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractSelectableChannel.html#blockingLock())() Retrieves the object upon which the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectableChannel.html#configureBlocking(boolean)` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectableChannel.html#register(java.nio.channels.Selector,%20int)` methods synchronize. |
| final [SelectableChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectableChannel.html) | [configureBlocking](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractSelectableChannel.html#configureBlocking(boolean))(boolean block) Adjusts this channel's blocking mode. |
| final void | [implCloseChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractSelectableChannel.html#implCloseChannel())() Closes this channel. |
| abstract void | [implCloseSelectableChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractSelectableChannel.html#implCloseSelectableChannel())() Closes this selectable channel. |
| abstract void | [implConfigureBlocking](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractSelectableChannel.html#implConfigureBlocking(boolean))(boolean block) Adjusts this channel's blocking mode. |
| final boolean | [isBlocking](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractSelectableChannel.html#isBlocking())() Tells whether or not every I/O operation on this channel will block until it completes. |
| final boolean | [isRegistered](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractSelectableChannel.html#isRegistered())() Tells whether or not this channel is currently registered with any selectors. |
| final [SelectionKey](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectionKey.html) | [keyFor](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractSelectableChannel.html#keyFor(java.nio.channels.Selector))([Selector](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Selector.html) sel) Retrieves the key representing the channel's registration with the given selector. |
| final [SelectorProvider](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/SelectorProvider.html) | [provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractSelectableChannel.html#provider())() Returns the provider that created this channel. |
| final [SelectionKey](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectionKey.html) | [register](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractSelectableChannel.html#register(java.nio.channels.Selector,%20int,%20java.lang.Object))([Selector](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Selector.html) sel, int ops, [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) att) Registers this channel with the given selector, returning a selection key. |

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

|---|---|
| abstract [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [blockingLock](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectableChannel.html#blockingLock())() Retrieves the object upon which the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectableChannel.html#configureBlocking(boolean)` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectableChannel.html#register(java.nio.channels.Selector,%20int)` methods synchronize. |
| abstract [SelectableChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectableChannel.html) | [configureBlocking](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectableChannel.html#configureBlocking(boolean))(boolean block) Adjusts this channel's blocking mode. |
| abstract boolean | [isBlocking](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectableChannel.html#isBlocking())() Tells whether or not every I/O operation on this channel will block until it completes. |
| abstract boolean | [isRegistered](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectableChannel.html#isRegistered())() Tells whether or not this channel is currently registered with any selectors. |
| abstract [SelectionKey](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectionKey.html) | [keyFor](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectableChannel.html#keyFor(java.nio.channels.Selector))([Selector](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Selector.html) sel) Retrieves the key representing the channel's registration with the given selector. |
| abstract [SelectorProvider](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/SelectorProvider.html) | [provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectableChannel.html#provider())() Returns the provider that created this channel. |
| abstract [SelectionKey](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectionKey.html) | [register](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectableChannel.html#register(java.nio.channels.Selector,%20int,%20java.lang.Object))([Selector](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Selector.html) sel, int ops, [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) att) Registers this channel with the given selector, returning a selection key. |
| final [SelectionKey](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectionKey.html) | [register](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectableChannel.html#register(java.nio.channels.Selector,%20int))([Selector](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Selector.html) sel, int ops) Registers this channel with the given selector, returning a selection key. |
| abstract int | [validOps](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectableChannel.html#validOps())() Returns an [operation set](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectionKey#opsets) identifying this channel's supported operations. |

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

|---|---|
| final void | [begin](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#begin())() Marks the beginning of an I/O operation that might block indefinitely. |
| final void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#close())() Closes this channel. |
| final void | [end](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#end(boolean))(boolean completed) Marks the end of an I/O operation that might block indefinitely. |
| abstract void | [implCloseChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#implCloseChannel())() Closes this channel. |
| final boolean | [isOpen](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#isOpen())() Tells whether or not this channel is open. |

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

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

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.nio.channels.InterruptibleChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/InterruptibleChannel.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/InterruptibleChannel.html#close())() Closes this channel. |

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

|---|---|
| abstract long | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ScatteringByteChannel.html#read(java.nio.ByteBuffer[],%20int,%20int))([ByteBuffer\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dsts, int offset, int length) Reads a sequence of bytes from this channel into a subsequence of the given buffers. |
| abstract long | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ScatteringByteChannel.html#read(java.nio.ByteBuffer[]))([ByteBuffer\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dsts) Reads a sequence of bytes from this channel into the given buffers. |

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

|---|---|
| abstract long | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/GatheringByteChannel.html#write(java.nio.ByteBuffer[]))([ByteBuffer\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) srcs) Writes a sequence of bytes to this channel from the given buffers. |
| abstract long | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/GatheringByteChannel.html#write(java.nio.ByteBuffer[],%20int,%20int))([ByteBuffer\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) srcs, int offset, int length) Writes a sequence of bytes to this channel from a subsequence of the given buffers. |

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

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MulticastChannel.html#close())() Closes this channel. |
| abstract [MembershipKey](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html) | [join](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MulticastChannel.html#join(java.net.InetAddress,%20java.net.NetworkInterface))([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) group, [NetworkInterface](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/NetworkInterface.html) interf) Joins a multicast group to begin receiving all datagrams sent to the group, returning a membership key. |
| abstract [MembershipKey](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html) | [join](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MulticastChannel.html#join(java.net.InetAddress,%20java.net.NetworkInterface,%20java.net.InetAddress))([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) group, [NetworkInterface](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/NetworkInterface.html) interf, [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) source) Joins a multicast group to begin receiving datagrams sent to the group from a given source address. |

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.nio.channels.ReadableByteChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ReadableByteChannel.html)

|---|---|
| abstract int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ReadableByteChannel.html#read(java.nio.ByteBuffer))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dst) Reads a sequence of bytes from this channel into the given buffer. |

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

|---|---|
| abstract int | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/WritableByteChannel.html#write(java.nio.ByteBuffer))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) src) Writes a sequence of bytes to this channel from the given buffer. |

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

|---|---|
| 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. |

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. |

## Protected Constructors

#### protected
**DatagramChannel**
([SelectorProvider](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/SelectorProvider.html) provider)

Initializes a new instance of this class.

##### Parameters

| provider | The provider that created this channel |
|---|---|

## Public Methods

#### public abstract [DatagramChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.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) |   |
| [UnsupportedAddressTypeException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/UnsupportedAddressTypeException.html) |   |
| [ClosedChannelException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedChannelException.html) |   |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) |   |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | If a security manager has been installed and its `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkListen(int)` method denies the operation |
|---|---|

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

Connects this channel's socket.

The channel's socket is configured so that it only receives
datagrams from, and sends datagrams to, the given remote *peer*
address. Once connected, datagrams may not be received from or sent to
any other address. A datagram socket remains connected until it is
explicitly disconnected or until it is closed.

This method performs exactly the same security checks as the `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocket.html#connect(java.net.InetAddress,%20int)` method of the `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocket.html` class. That is, if a security manager has been
installed then this method verifies that its `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkAccept(java.lang.String,%20int)` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkConnect(java.lang.String,%20int)` methods permit
datagrams to be received from and sent to, respectively, the given
remote address.

This method may be invoked at any time. It will not have any effect
on read or write operations that are already in progress at the moment
that it is invoked. If this channel's socket is not bound then this method
will first cause the socket to be bound to an address that is assigned
automatically, as if invoking the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#bind(java.net.SocketAddress)` method with a
parameter of `null`.

<br />

##### Parameters

| remote | The remote address to which this channel is to be connected |
|---|---|

##### Returns

- This datagram channel

##### Throws

| [ClosedChannelException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedChannelException.html) | If this channel is closed |
| [AsynchronousCloseException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousCloseException.html) | If another thread closes this channel while the connect operation is in progress |
| [ClosedByInterruptException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedByInterruptException.html) | 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 |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | If a security manager has been installed and it does not permit access to the given remote address |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If some other I/O error occurs |
|---|---|

#### public abstract [DatagramChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html)
**disconnect**
()

Disconnects this channel's socket.

The channel's socket is configured so that it can receive datagrams
from, and sends datagrams to, any remote address so long as the security
manager, if installed, permits it.

This method may be invoked at any time. It will not have any effect
on read or write operations that are already in progress at the moment
that it is invoked.

If this channel's socket is not connected, or if the channel is
closed, then invoking this method has no effect.

<br />

##### Returns

- This datagram channel

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If some other I/O error occurs |
|---|---|

#### 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`.


If there is a security manager set, its `checkConnect` method is
called with the local address and `-1` as its arguments to see
if the operation is allowed. If the operation is not allowed,
a `SocketAddress` representing the
`https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html#getLoopbackAddress()` address and the
local port of the channel's socket is returned.

##### Returns

- The `SocketAddress` that the socket is bound to, or the `SocketAddress` representing the loopback address if denied by the security manager, 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) |   |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) |   |
|---|---|

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

Returns the remote address to which this channel's socket is connected.

##### Returns

- The remote address; `null` if the channel's socket is not connected

##### 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 boolean
**isConnected**
()

Tells whether or not this channel's socket is connected.

##### Returns

- `true` if, and only if, this channel's socket is `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#isOpen()` and connected

#### public static [DatagramChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html)
**open**
()

Opens a datagram channel.

The new channel is created by invoking the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/SelectorProvider.html#openDatagramChannel()` method of the system-wide default `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/SelectorProvider.html` object. The channel will not be
connected.

The `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProtocolFamily.html` of the channel's socket
is platform (and possibly configuration) dependent and therefore unspecified.
The `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#open(java.net.ProtocolFamily)` allows the protocol family to be
selected when opening a datagram channel, and should be used to open
datagram channels that are intended for Internet Protocol multicasting.

##### Returns

- A new datagram channel

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If an I/O error occurs |
|---|---|

#### public static [DatagramChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html)
**open**
([ProtocolFamily](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProtocolFamily.html) family)

Opens a datagram channel.

The `family` parameter is used to specify the `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProtocolFamily.html`. If the datagram channel is to be used for IP multicasting
then this should correspond to the address type of the multicast groups
that this channel will join.

The new channel is created by invoking the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/SelectorProvider.html#openDatagramChannel(java.net.ProtocolFamily)` method of the system-wide default `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/SelectorProvider.html` object. The channel will not be
connected.

##### Parameters

| family | The protocol family |
|---|---|

##### Returns

- A new datagram channel

##### Throws

| [UnsupportedOperationException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/UnsupportedOperationException.html) | If the specified protocol family is not supported. For example, suppose the parameter is specified as `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/StandardProtocolFamily.html#INET6` but IPv6 is not enabled on the platform. |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If an I/O error occurs |
|---|---|

#### public abstract long
**read**
([ByteBuffer\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dsts, int offset, int length)

Reads a datagram from this channel.

This method may only be invoked if this channel's socket is
connected, and it only accepts datagrams from the socket's peer. If
there are more bytes in the datagram than remain in the given buffers
then the remainder of the datagram is silently discarded. Otherwise
this method behaves exactly as specified in the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ScatteringByteChannel.html` interface.

<br />

##### Parameters

| dsts | The buffers into which bytes are to be transferred |
| offset | The offset within the buffer array of the first buffer into which bytes are to be transferred; must be non-negative and no larger than dsts.length |
| length | The maximum number of buffers to be accessed; must be non-negative and no larger than dsts.length - offset |
|---|---|

##### Returns

- The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream

##### Throws

| [NotYetConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NotYetConnectedException.html) | If this channel's socket is not connected |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) |   |
|---|---|

#### public abstract int
**read**
([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dst)

Reads a datagram from this channel.

This method may only be invoked if this channel's socket is
connected, and it only accepts datagrams from the socket's peer. If
there are more bytes in the datagram than remain in the given buffer
then the remainder of the datagram is silently discarded. Otherwise
this method behaves exactly as specified in the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ReadableByteChannel.html` interface.

<br />

##### Parameters

| dst | The buffer into which bytes are to be transferred |
|---|---|

##### Returns

- The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream

##### Throws

| [NotYetConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NotYetConnectedException.html) | If this channel's socket is not connected |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) |   |
|---|---|

#### public final long
**read**
([ByteBuffer\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dsts)

Reads a datagram from this channel.

This method may only be invoked if this channel's socket is
connected, and it only accepts datagrams from the socket's peer. If
there are more bytes in the datagram than remain in the given buffers
then the remainder of the datagram is silently discarded. Otherwise
this method behaves exactly as specified in the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ScatteringByteChannel.html` interface.

<br />

##### Parameters

| dsts | The buffers into which bytes are to be transferred |
|---|---|

##### Returns

- The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream

##### Throws

| [NotYetConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NotYetConnectedException.html) | If this channel's socket is not connected |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) |   |
|---|---|

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

Receives a datagram via this channel.

If a datagram is immediately available, or if this channel is in
blocking mode and one eventually becomes available, then the datagram is
copied into the given byte buffer and its source address is returned.
If this channel is in non-blocking mode and a datagram is not
immediately available then this method immediately returns
null.

The datagram is transferred into the given byte buffer starting at
its current position, as if by a regular `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ReadableByteChannel.html#read(java.nio.ByteBuffer)` operation. If there
are fewer bytes remaining in the buffer than are required to hold the
datagram then the remainder of the datagram is silently discarded.

This method performs exactly the same security checks as the `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocket.html#receive(java.net.DatagramPacket)` method of the `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocket.html` class. That is, if the socket is not connected
to a specific remote address and a security manager has been installed
then for each datagram received this method verifies that the source's
address and port number are permitted by the security manager's `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkAccept(java.lang.String,%20int)` method. The overhead
of this security check can be avoided by first connecting the socket via
the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#connect(java.net.SocketAddress)` method.

This method may be invoked at any time. If another thread has
already initiated a read operation upon this channel, however, then an
invocation of this method will block until the first operation is
complete. If this channel's socket is not bound then this method will
first cause the socket to be bound to an address that is assigned
automatically, as if invoking the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#bind(java.net.SocketAddress)` method with a
parameter of `null`.

<br />

##### Parameters

| dst | The buffer into which the datagram is to be transferred |
|---|---|

##### Returns

- The datagram's source address, or null if this channel is in non-blocking mode and no datagram was immediately available

##### Throws

| [ClosedChannelException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedChannelException.html) | If this channel is closed |
| [AsynchronousCloseException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousCloseException.html) | If another thread closes this channel while the read operation is in progress |
| [ClosedByInterruptException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedByInterruptException.html) | If another thread interrupts the current thread while the read operation is in progress, thereby closing the channel and setting the current thread's interrupt status |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | If a security manager has been installed and it does not permit datagrams to be accepted from the datagram's sender |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If some other I/O error occurs |
|---|---|

#### public abstract int
**send**
([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) src, [SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) target)

Sends a datagram via this channel.

If this channel is in non-blocking mode and there is sufficient room
in the underlying output buffer, or if this channel is in blocking mode
and sufficient room becomes available, then the remaining bytes in the
given buffer are transmitted as a single datagram to the given target
address.

The datagram is transferred from the byte buffer as if by a regular
`https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/WritableByteChannel.html#write(java.nio.ByteBuffer)` operation.

This method performs exactly the same security checks as the `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocket.html#send(java.net.DatagramPacket)` method of the `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocket.html` class. That is, if the socket is not connected
to a specific remote address and a security manager has been installed
then for each datagram sent this method verifies that the target address
and port number are permitted by the security manager's `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkConnect(java.lang.String,%20int)` method. The
overhead of this security check can be avoided by first connecting the
socket via the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#connect(java.net.SocketAddress)` method.

This method may be invoked at any time. If another thread has
already initiated a write operation upon this channel, however, then an
invocation of this method will block until the first operation is
complete. If this channel's socket is not bound then this method will
first cause the socket to be bound to an address that is assigned
automatically, as if by invoking the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html#bind(java.net.SocketAddress)` method with a
parameter of `null`.

<br />

##### Parameters

| src | The buffer containing the datagram to be sent |
| target | The address to which the datagram is to be sent |
|---|---|

##### Returns

- The number of bytes sent, which will be either the number of bytes that were remaining in the source buffer when this method was invoked or, if this channel is non-blocking, may be zero if there was insufficient room for the datagram in the underlying output buffer

##### Throws

| [ClosedChannelException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedChannelException.html) | If this channel is closed |
| [AsynchronousCloseException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousCloseException.html) | If another thread closes this channel while the read operation is in progress |
| [ClosedByInterruptException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedByInterruptException.html) | If another thread interrupts the current thread while the read operation is in progress, thereby closing the channel and setting the current thread's interrupt status |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | If a security manager has been installed and it does not permit datagrams to be sent to the given address |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If some other I/O error occurs |
|---|---|

#### public abstract [DatagramChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.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) |   |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) |   |
| [ClosedChannelException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedChannelException.html) |   |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) |   |
|---|---|

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

Retrieves a datagram socket associated with this channel.

The returned object will not declare any public methods that are not
declared in the `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocket.html` class.

<br />

##### Returns

- A datagram socket associated with this channel

#### public final int
**validOps**
()

Returns an operation set identifying this channel's supported
operations.

Datagram channels support reading and writing, so this method
returns (`https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectionKey.html#OP_READ` \| `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectionKey.html#OP_WRITE`).

<br />

##### Returns

- The valid-operation set

#### public abstract int
**write**
([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) src)

Writes a datagram to this channel.

This method may only be invoked if this channel's socket is
connected, in which case it sends datagrams directly to the socket's
peer. Otherwise it behaves exactly as specified in the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/WritableByteChannel.html` interface.

<br />

##### Parameters

| src | The buffer from which bytes are to be retrieved |
|---|---|

##### Returns

- The number of bytes written, possibly zero

##### Throws

| [NotYetConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NotYetConnectedException.html) | If this channel's socket is not connected |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) |   |
|---|---|

#### public final long
**write**
([ByteBuffer\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) srcs)

Writes a datagram to this channel.

This method may only be invoked if this channel's socket is
connected, in which case it sends datagrams directly to the socket's
peer. Otherwise it behaves exactly as specified in the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/GatheringByteChannel.html` interface.

<br />

##### Parameters

| srcs | The buffers from which bytes are to be retrieved |
|---|---|

##### Returns

- The number of bytes sent, which will be either the number of bytes that were remaining in the source buffer when this method was invoked or, if this channel is non-blocking, may be zero if there was insufficient room for the datagram in the underlying output buffer

##### Throws

| [NotYetConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NotYetConnectedException.html) | If this channel's socket is not connected |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) |   |
|---|---|

#### public abstract long
**write**
([ByteBuffer\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) srcs, int offset, int length)

Writes a datagram to this channel.

This method may only be invoked if this channel's socket is
connected, in which case it sends datagrams directly to the socket's
peer. Otherwise it behaves exactly as specified in the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/GatheringByteChannel.html` interface.

<br />

##### Parameters

| srcs | The buffers from which bytes are to be retrieved |
| offset | The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than srcs.length |
| length | The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset |
|---|---|

##### Returns

- The number of bytes sent, which will be either the number of bytes that were remaining in the source buffer when this method was invoked or, if this channel is non-blocking, may be zero if there was insufficient room for the datagram in the underlying output buffer

##### Throws

| [NotYetConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NotYetConnectedException.html) | If this channel's socket is not connected |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) |   |
|---|---|