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.

    protected

    Creates an unbound datagram socket with the specified DatagramSocketImpl.

    Creates a datagram socket, bound to the specified local socket address.

  • Method Summary

    void

    Binds this DatagramSocket to a specific address and port.

    void

    close()

    Closes this datagram socket.

    void

    Connects the socket to a remote address for this socket.

    void

    Connects this socket to a remote socket address (IP address + port number).

    void

    boolean

    Tests if SO_BROADCAST is enabled.

    Returns the unique DatagramChannel object 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.

    int

    Returns 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> T

    Returns the value of a socket option.

    int

    getPort()

    Returns the port number to which this socket is connected.

    int

    Get value of the SO_RCVBUF option for this DatagramSocket, that is the buffer size, in bytes, used by the platform for input on this DatagramSocket.

    Returns the address of the endpoint this socket is connected to, or null if it is unconnected.

    boolean

    Tests if SO_REUSEADDR is enabled.

    int

    Get value of the SO_SNDBUF option for this DatagramSocket, that is the buffer size, in bytes, used by the platform for output on this DatagramSocket.

    int

    Retrieve setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).

    int

    Gets traffic class or type-of-service in the IP datagram header for packets sent from this DatagramSocket.

    boolean

    isBound()

    Returns the binding state of the socket.

    boolean

    isClosed()

    Returns whether the socket is closed or not.

    boolean

    Returns the connection state of the socket.

    void

    void

    Leave a multicast group on a specified local interface.

    void

    Receives a datagram packet from this socket.

    void

    Sends a datagram packet from this socket.

    void

    setBroadcast(boolean on)

    Enable/disable SO_BROADCAST.

    static void

    Sets the value of a socket option.

    void

    setReceiveBufferSize(int size)

    Sets the SO_RCVBUF option to the specified value for this DatagramSocket.

    void

    setReuseAddress(boolean on)

    Enable/disable the SO_REUSEADDR socket option.

    void

    setSendBufferSize(int size)

    Sets the SO_SNDBUF option to the specified value for this DatagramSocket.

    void

    setSoTimeout(int timeout)

    Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.

    void

    setTrafficClass(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