public class PlainDatagramSocketImpl extends DatagramSocketImpl
fd, localPortIP_MULTICAST_IF, IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS, SO_BINDADDR, SO_BROADCAST, SO_KEEPALIVE, SO_LINGER, SO_OOBINLINE, SO_RCVBUF, SO_REUSEADDR, SO_REUSEPORT, SO_SNDBUF, SO_TIMEOUT, TCP_NODELAY| Constructor and Description |
|---|
PlainDatagramSocketImpl() |
PlainDatagramSocketImpl(FileDescriptor fd,
int localPort) |
| Modifier and Type | Method and Description |
|---|---|
void |
bind(int port,
InetAddress address)
Binds the datagram socket to the given local host/port.
|
void |
close()
Closes this socket.
|
void |
connect(InetAddress inetAddr,
int port)
Connects this socket to the specified remote address and port.
|
void |
create()
This method allocates the socket descriptor in the underlying operating
system.
|
void |
disconnect()
Disconnects this socket from the remote host.
|
protected void |
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
Object |
getOption(int option)
Gets the value for the specified socket option.
|
int |
getTimeToLive()
Gets the time-to-live (TTL) for multicast packets sent on this socket.
|
byte |
getTTL()
Gets the time-to-live (TTL) for multicast packets sent on this socket.
|
void |
join(InetAddress addr)
Adds this socket to the multicast group
addr. |
void |
joinGroup(SocketAddress addr,
NetworkInterface netInterface)
Adds this socket to the multicast group
addr. |
void |
leave(InetAddress addr)
Removes this socket from the multicast group
addr. |
void |
leaveGroup(SocketAddress addr,
NetworkInterface netInterface)
Removes this socket from the multicast group
addr. |
protected void |
onBind(InetAddress localAddress,
int localPort)
Initialize the bind() state.
|
protected void |
onClose()
Initialize the closed state.
|
protected void |
onConnect(InetAddress remoteAddress,
int remotePort)
Initialize the connect() state.
|
protected void |
onDisconnect()
Initialize the disconnected state.
|
protected int |
peek(InetAddress sender)
Peeks at the incoming packet to this socket and returns the address of
the
sender. |
int |
peekData(DatagramPacket pack)
Receives data into the supplied datagram packet by peeking.
|
void |
receive(DatagramPacket pack)
Receives data and stores it in the supplied datagram packet
pack. |
void |
send(DatagramPacket packet)
Sends the given datagram packet
pack. |
void |
setOption(int option,
Object value)
Sets the value of the specified socket option.
|
void |
setTimeToLive(int ttl)
Sets the time-to-live (TTL) option for multicast packets sent on this
socket.
|
void |
setTTL(byte ttl)
Sets the time-to-live (TTL) option for multicast packets sent on this
socket.
|
getFileDescriptor, getLocalPortpublic PlainDatagramSocketImpl(FileDescriptor fd, int localPort)
public PlainDatagramSocketImpl()
public void bind(int port,
InetAddress address)
throws SocketException
DatagramSocketImplbind in class DatagramSocketImplport - the port on the local host to bind to.address - the address on the multihomed local host to bind to.SocketException - if an error occurs while binding, for example, if the port
has been already bound.protected void onBind(InetAddress localAddress, int localPort)
DatagramSocketImplonBind in class DatagramSocketImplpublic void close()
DatagramSocketImplclose in class DatagramSocketImplprotected void onClose()
DatagramSocketImplonClose in class DatagramSocketImplpublic void create()
throws SocketException
DatagramSocketImplcreate in class DatagramSocketImplSocketException - if an error occurs while creating the socket.protected void finalize()
throws Throwable
ObjectNote that objects that override finalize are significantly more expensive than
objects that don't. Finalizers may be run a long time after the object is no longer
reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup.
Note also that finalizers are run on a single VM-wide finalizer thread,
so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary
for a class that has a native peer and needs to call a native method to destroy that peer.
Even then, it's better to provide an explicit close method (and implement
Closeable), and insist that callers manually dispose of instances. This
works well for something like files, but less well for something like a BigInteger
where typical calling code would have to deal with lots of temporaries. Unfortunately,
code that creates lots of temporaries is the worst kind of code from the point of view of
the single finalizer thread.
If you must use finalizers, consider at least providing your own
ReferenceQueue and having your own thread process that queue.
Unlike constructors, finalizers are not automatically chained. You are responsible for
calling super.finalize() yourself.
Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.
public Object getOption(int option) throws SocketException
SocketOptionsoption - the option identifier.SocketException - if an error occurs reading the option value.public int getTimeToLive()
throws IOException
DatagramSocketImplgetTimeToLive in class DatagramSocketImplIOException - if an error occurs while getting the time-to-live option
value.public byte getTTL()
throws IOException
DatagramSocketImplgetTTL in class DatagramSocketImplIOException - if an error occurs while getting the time-to-live option
value.DatagramSocketImpl.getTimeToLive()public void join(InetAddress addr) throws IOException
DatagramSocketImpladdr. A socket must join
a group before being able to receive data. Further, a socket may be a
member of multiple groups but may join any group only once.join in class DatagramSocketImpladdr - the multicast group to which this socket has to be joined.IOException - if an error occurs while joining the specified multicast
group.public void joinGroup(SocketAddress addr, NetworkInterface netInterface) throws IOException
DatagramSocketImpladdr. A socket must join
a group before being able to receive data. Further, a socket may be a
member of multiple groups but may join any group only once.joinGroup in class DatagramSocketImpladdr - the multicast group to which this socket has to be joined.netInterface - the local network interface which will receive the multicast
datagram packets.IOException - if an error occurs while joining the specified multicast
group.public void leave(InetAddress addr) throws IOException
DatagramSocketImpladdr.leave in class DatagramSocketImpladdr - the multicast group to be left.IOException - if an error occurs while leaving the group or no multicast
address was assigned.public void leaveGroup(SocketAddress addr, NetworkInterface netInterface) throws IOException
DatagramSocketImpladdr.leaveGroup in class DatagramSocketImpladdr - the multicast group to be left.netInterface - the local network interface on which this socket has to be
removed.IOException - if an error occurs while leaving the group.protected int peek(InetAddress sender) throws IOException
DatagramSocketImplsender. The method will block until a packet is received or
timeout expires.peek in class DatagramSocketImplsender - the origin address of a packet.sender as an integer value.IOException - if an error or a timeout occurs while reading the address.public void receive(DatagramPacket pack) throws IOException
DatagramSocketImplpack.
This call will block until either data has been received or, if a timeout
is set, the timeout has expired. If the timeout expires an InterruptedIOException is thrown.receive in class DatagramSocketImplpack - the datagram packet container to fill in the received data.IOException - if an error or timeout occurs while receiving data.public int peekData(DatagramPacket pack) throws IOException
DatagramSocketImplpeekData() or receive() call. This call blocks until
either data has been received or, if a timeout is set, the timeout has
been expired.peekData in class DatagramSocketImplpack - the datagram packet used to store the data.IOException - if an error occurs while peeking at the data.public void send(DatagramPacket packet) throws IOException
DatagramSocketImplpack. The packet contains the
data and the address and port information of the target host as well.send in class DatagramSocketImplpacket - the datagram packet to be sent.IOException - if an error occurs while sending the packet.public void setOption(int option,
Object value)
throws SocketException
SocketOptionsoption - the option identifier.value - the value to be set for the option.SocketException - if an error occurs setting the option value.public void setTimeToLive(int ttl)
throws IOException
DatagramSocketImplsetTimeToLive in class DatagramSocketImplttl - the time-to-live option value. Valid values are 0 < ttl
<= 255.IOException - if an error occurs while setting the option.public void setTTL(byte ttl)
throws IOException
DatagramSocketImplsetTTL in class DatagramSocketImplttl - the time-to-live option value. Valid values are 0 < ttl
<= 255.IOException - if an error occurs while setting the option.DatagramSocketImpl.setTimeToLive(int)public void connect(InetAddress inetAddr, int port) throws SocketException
DatagramSocketImplconnect in class DatagramSocketImplinetAddr - the address of the target host which has to be connected.port - the port on the target host which has to be connected.SocketException - if the datagram socket cannot be connected to the
specified remote address and port.protected void onConnect(InetAddress remoteAddress, int remotePort)
DatagramSocketImplonConnect in class DatagramSocketImplpublic void disconnect()
DatagramSocketImpldisconnect in class DatagramSocketImplprotected void onDisconnect()
DatagramSocketImplonDisconnect in class DatagramSocketImpl