SocketOptions
public abstract class DatagramSocketImpl extends Object implements SocketOptions
Modifier and Type | Field | Description |
---|---|---|
protected FileDescriptor |
fd |
The file descriptor object. |
protected int |
localPort |
The local port number. |
IP_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 | Description |
---|---|
DatagramSocketImpl() |
Constructor for subclasses to call. |
Modifier and Type | Method | Description |
---|---|---|
protected abstract void |
bind |
Binds a datagram socket to a local port and address. |
protected abstract void |
close() |
Close the socket. |
protected void |
connect |
Connects a datagram socket to a remote destination. |
protected abstract void |
create() |
Creates a datagram socket. |
protected void |
disconnect() |
Disconnects a datagram socket from its remote destination. |
protected FileDescriptor |
getFileDescriptor() |
Gets the datagram socket file descriptor. |
protected int |
getLocalPort() |
Gets the local port. |
protected <T> T |
getOption |
Called to get a socket option. |
protected abstract int |
getTimeToLive() |
Retrieve the TTL (time-to-live) option. |
protected abstract byte |
getTTL() |
Deprecated. use getTimeToLive instead. |
protected abstract void |
join |
Join the multicast group. |
protected abstract void |
joinGroup |
Join the multicast group. |
protected abstract void |
leave |
Leave the multicast group. |
protected abstract void |
leaveGroup |
Leave the multicast group. |
protected abstract int |
peek |
Peek at the packet to see who it is from. |
protected abstract int |
peekData |
Peek at the packet to see who it is from. |
protected abstract void |
receive |
Receive the datagram packet. |
protected abstract void |
send |
Sends a datagram packet. |
protected <T> void |
setOption |
Called to set a socket option. |
protected abstract void |
setTimeToLive |
Set the TTL (time-to-live) option. |
protected abstract void |
setTTL |
Deprecated. use setTimeToLive instead. |
protected Set |
supportedOptions() |
Returns a set of SocketOptions supported by this impl and by this impl's socket (DatagramSocket or MulticastSocket) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getOption, setOption
protected int localPort
protected FileDescriptor fd
public DatagramSocketImpl()
protected abstract void create() throws SocketException
SocketException
- if there is an error in the underlying protocol, such as a TCP error.protected abstract void bind(int lport, InetAddress laddr) throws SocketException
lport
- the local portladdr
- the local addressSocketException
- if there is an error in the underlying protocol, such as a TCP error.protected abstract void send(DatagramPacket p) throws IOException
p
- the packet to be sent.IOException
- if an I/O exception occurs while sending the datagram packet.PortUnreachableException
- may be thrown if the socket is connected to a currently unreachable destination. Note, there is no guarantee that the exception will be thrown.protected void connect(InetAddress address, int port) throws SocketException
If the remote destination to which the socket is connected does not exist, or is otherwise unreachable, and if an ICMP destination unreachable packet has been received for that address, then a subsequent call to send or receive may throw a PortUnreachableException. Note, there is no guarantee that the exception will be thrown.
SocketException
.address
- the remote InetAddress to connect toport
- the remote port numberSocketException
- may be thrown if the socket cannot be connected to the remote destinationprotected void disconnect()
UncheckedIOException
.UncheckedIOException
- if disconnect fails or no implementation is providedprotected abstract int peek(InetAddress i) throws IOException
InetAddress
to the address which the packet came from.i
- an InetAddress objectIOException
- if an I/O exception occursPortUnreachableException
- may be thrown if the socket is connected to a currently unreachable destination. Note, there is no guarantee that the exception will be thrown.protected abstract int peekData(DatagramPacket p) throws IOException
DatagramPacket
. The data is returned, but not consumed, so that a subsequent peekData/receive operation will see the same data.p
- the Packet Received.IOException
- if an I/O exception occursPortUnreachableException
- may be thrown if the socket is connected to a currently unreachable destination. Note, there is no guarantee that the exception will be thrown.protected abstract void receive(DatagramPacket p) throws IOException
p
- the Packet Received.IOException
- if an I/O exception occurs while receiving the datagram packet.PortUnreachableException
- may be thrown if the socket is connected to a currently unreachable destination. Note, there is no guarantee that the exception will be thrown.@Deprecated protected abstract void setTTL(byte ttl) throws IOException
ttl
- a byte specifying the TTL valueIOException
- if an I/O exception occurs while setting the time-to-live option.@Deprecated protected abstract byte getTTL() throws IOException
IOException
- if an I/O exception occurs while retrieving the time-to-live optionprotected abstract void setTimeToLive(int ttl) throws IOException
ttl
- an int
specifying the time-to-live valueIOException
- if an I/O exception occurs while setting the time-to-live option.protected abstract int getTimeToLive() throws IOException
int
representing the time-to-live valueIOException
- if an I/O exception occurs while retrieving the time-to-live optionprotected abstract void join(InetAddress inetaddr) throws IOException
inetaddr
- multicast address to join.IOException
- if an I/O exception occurs while joining the multicast group.protected abstract void leave(InetAddress inetaddr) throws IOException
inetaddr
- multicast address to leave.IOException
- if an I/O exception occurs while leaving the multicast group.protected abstract void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException
mcastaddr
- address to join.netIf
- specifies the local interface to receive multicast datagram packetsIOException
- if an I/O exception occurs while joining the multicast groupprotected abstract void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException
mcastaddr
- address to leave.netIf
- specified the local interface to leave the group atIOException
- if an I/O exception occurs while leaving the multicast groupprotected abstract void close()
protected int getLocalPort()
int
representing the local port valueprotected FileDescriptor getFileDescriptor()
FileDescriptor
object representing the datagram socket file descriptorprotected <T> void setOption(SocketOption<T> name, T value) throws IOException
name
is not null, then throws
UnsupportedOperationException
. Subclasses should override this method with an appropriate implementation.T
- The type of the socket option valuename
- The socket optionvalue
- The value of the socket option. A value of null
may be valid for some options.UnsupportedOperationException
- if the DatagramSocketImpl does not support the optionIllegalArgumentException
- if the value is not valid for the optionIOException
- if an I/O error occurs, or if the socket is closedNullPointerException
- if name is null
protected <T> T getOption(SocketOption<T> name) throws IOException
name
is not null, then throws
UnsupportedOperationException
. Subclasses should override this method with an appropriate implementation.T
- The type of the socket option valuename
- The socket optionUnsupportedOperationException
- if the DatagramSocketImpl does not support the optionIOException
- if an I/O error occurs, or if the socket is closedNullPointerException
- if name is null
protected Set<SocketOption<?>> supportedOptions()
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/net/DatagramSocketImpl.html