|
NIO2 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.nio.channels.spi.AbstractInterruptibleChannel
java.nio.channels.SelectableChannel
java.nio.channels.spi.AbstractSelectableChannel
java.nio.channels.DatagramChannel
org.classpath.icedtea.java.nio.channels.DatagramChannel
public abstract class DatagramChannel
A selectable channel for datagram-oriented sockets.
A datagram channel is created by invoking one of the 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 send
and receive
methods to be used. A datagram channel may be
connected, by invoking its connect
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 read
and write
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 isConnected
method.
Socket options are configured using the setOption
method. A datagram channel to an Internet Protocol socket supports
the following options:
Additional (implementation specific) options may also be supported.
Option Name Description SO_SNDBUF
The size of the socket send buffer SO_RCVBUF
The size of the socket receive buffer SO_REUSEADDR
Re-use address SO_BROADCAST
Allow transmission of broadcast datagrams IP_TOS
The Type of Service (ToS) octet in the Internet Protocol (IP) header IP_MULTICAST_IF
The network interface for Internet Protocol (IP) multicast datagrams IP_MULTICAST_TTL
The time-to-live for Internet Protocol (IP) multicast datagrams IP_MULTICAST_LOOP
Loopback for Internet Protocol (IP) multicast datagrams
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.
Constructor Summary | |
---|---|
protected |
DatagramChannel(SelectorProvider provider)
Initializes a new instance of this class. |
Method Summary | ||
---|---|---|
abstract DatagramChannel |
bind(SocketAddress local)
Binds the channel's socket to a local address. |
|
abstract SocketAddress |
getRemoteAddress()
Returns the remote address to which this channel's socket is connected. |
|
static DatagramChannel |
open()
Opens a datagram channel. |
|
static DatagramChannel |
open(ProtocolFamily family)
Opens a datagram channel. |
|
abstract
|
setOption(SocketOption<T> name,
T value)
Sets the value of a socket option. |
Methods inherited from class java.nio.channels.DatagramChannel |
---|
connect, disconnect, isConnected, read, read, read, receive, send, socket, validOps, write, write, write |
Methods inherited from class java.nio.channels.spi.AbstractSelectableChannel |
---|
blockingLock, configureBlocking, implCloseChannel, implCloseSelectableChannel, implConfigureBlocking, isBlocking, isRegistered, keyFor, provider, register |
Methods inherited from class java.nio.channels.SelectableChannel |
---|
register |
Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel |
---|
begin, close, end, isOpen |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.classpath.icedtea.java.nio.channels.MulticastChannel |
---|
join, join |
Methods inherited from interface org.classpath.icedtea.java.nio.channels.NetworkChannel |
---|
getLocalAddress, getOption, supportedOptions |
Methods inherited from interface java.nio.channels.Channel |
---|
close, isOpen |
Constructor Detail |
---|
protected DatagramChannel(SelectorProvider provider)
Method Detail |
---|
public static DatagramChannel open() throws IOException
The new channel is created by invoking the openDatagramChannel
method of the system-wide default SelectorProvider
object. The channel will not be
connected.
IOException
- If an I/O error occurspublic static DatagramChannel open(ProtocolFamily family) throws IOException
The family
parameter is used to specify the ProtocolFamily
. If the datagram channel is to be used for IP multicasing
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 openDatagramChannel
method of the system-wide default SelectorProvider
object. The channel will not be
connected.
family
- The protocol family
UnsupportedOperationException
- If the specified protocol family is not supported. For example,
suppose the parameter is specified as StandardProtocolFamily.INET6
but IPv6 is not enabled on the platform.
IOException
- If an I/O error occurspublic abstract DatagramChannel bind(SocketAddress local) throws IOException
NetworkChannel
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.
bind
in interface NetworkChannel
local
- The address to bind the socket, or null
to bind the socket
to an automatically assigned socket address
AlreadyBoundException
- If the socket is already bound
UnsupportedAddressTypeException
- If the type of the given address is not supported
ClosedChannelException
- If the channel is closed
IOException
- If some other I/O error occurs
SecurityException
- If a security manager has been installed and its checkListen
method denies the
operationNetworkChannel.getLocalAddress()
public abstract <T> DatagramChannel setOption(SocketOption<T> name, T value) throws IOException
NetworkChannel
setOption
in interface NetworkChannel
name
- The socket optionvalue
- The value of the socket option. A value of null
may be
a valid value for some socket options.
IllegalArgumentException
- If the value is not a valid value for this socket option
ClosedChannelException
- If this channel is closed
IOException
- If an I/O error occursStandardSocketOption
public abstract SocketAddress getRemoteAddress() throws IOException
null
if the channel's socket is not
connected
ClosedChannelException
- If the channel is closed
IOException
- If an I/O error occurs
|
NIO2 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2007, 2011, Oracle and/or its affiliates. All rights reserved.