DatagramSocket (Java SE 25 & JDK 25)
- All Implemented Interfaces:
Closeable, AutoCloseable
- Direct Known Subclasses:
MulticastSocket
-
Constructor Summary
Constructors
Constructs a datagram socket and binds it to any available port on the local host machine.
DatagramSocket(int port) Constructs a datagram socket and binds it to the specified port on the local host machine.
Creates a datagram socket, bound to the specified local address.
protectedCreates an unbound datagram socket with the specified DatagramSocketImpl.
Creates a datagram socket, bound to the specified local socket address.
-
Method Summary
voidBinds this DatagramSocket to a specific address and port.
voidclose()Closes this datagram socket.
voidConnects the socket to a remote address for this socket.
voidConnects this socket to a remote socket address (IP address + port number).
voidbooleanTests if SO_BROADCAST is enabled.
Returns the unique
DatagramChannelobject associated with this datagram socket, if any.Returns the address to which this socket is connected.
Gets the local address to which the socket is bound.
intReturns the port number on the local host to which this socket is bound.
Returns the address of the endpoint this socket is bound to.
<T> TReturns the value of a socket option.
intgetPort()Returns the port number to which this socket is connected.
intGet value of the SO_RCVBUF option for this
DatagramSocket, that is the buffer size, in bytes, used by the platform for input on thisDatagramSocket.Returns the address of the endpoint this socket is connected to, or
nullif it is unconnected.booleanTests if SO_REUSEADDR is enabled.
intGet value of the SO_SNDBUF option for this
DatagramSocket, that is the buffer size, in bytes, used by the platform for output on thisDatagramSocket.intRetrieve setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).
intGets traffic class or type-of-service in the IP datagram header for packets sent from this DatagramSocket.
booleanisBound()Returns the binding state of the socket.
booleanisClosed()Returns whether the socket is closed or not.
booleanReturns the connection state of the socket.
voidvoidLeave a multicast group on a specified local interface.
voidReceives a datagram packet from this socket.
voidSends a datagram packet from this socket.
voidsetBroadcast(boolean on) Enable/disable SO_BROADCAST.
static voidSets the value of a socket option.
voidsetReceiveBufferSize(int size) Sets the SO_RCVBUF option to the specified value for this
DatagramSocket.voidsetReuseAddress(boolean on) Enable/disable the SO_REUSEADDR socket option.
voidsetSendBufferSize(int size) Sets the SO_SNDBUF option to the specified value for this
DatagramSocket.voidsetSoTimeout(int timeout) Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
voidsetTrafficClass(int tc) Sets traffic class or type-of-service octet in the IP datagram header for datagrams sent from this DatagramSocket.
Returns a set of the socket options supported by this socket.
-
Constructor Details
-
DatagramSocket
-
DatagramSocket
-
DatagramSocket
-
DatagramSocket
-
DatagramSocket
-
-
Method Details
-
bind
-
connect
-
connect
-
disconnect
-
isBound
-
isConnected
-
getInetAddress
-
getPort
-
getRemoteSocketAddress
-
getLocalSocketAddress
-
send
-
receive
-
getLocalAddress
-
getLocalPort
-
setSoTimeout
-
getSoTimeout
-
setSendBufferSize
-
getSendBufferSize
-
setReceiveBufferSize
-
getReceiveBufferSize
-
setReuseAddress
-
getReuseAddress
-
setBroadcast
-
getBroadcast
-
setTrafficClass
-
getTrafficClass
-
close
-
isClosed
-
getChannel
-
setDatagramSocketImplFactory
-
setOption
-
getOption
-
supportedOptions
-
joinGroup
-
leaveGroup
-