Package 

Class MultiplexingDatagramSocket

  • All Implemented Interfaces:
    java.io.Closeable , java.lang.AutoCloseable

    
    public class MultiplexingDatagramSocket
    extends SafeCloseDatagramSocket
                        

    Represents a DatagramSocket which allows filtering DatagramPackets it reads from the network using DatagramPacketFilters so that the DatagramPackets do not get received through it but through associated MultiplexedDatagramSockets.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int soTimeout
    • Constructor Summary

      Constructors 
      Constructor Description
      MultiplexingDatagramSocket() Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering and binds it to any available port on the local host machine.
      MultiplexingDatagramSocket(boolean persistent) Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering and binds it to any available port on the local host machine.
      MultiplexingDatagramSocket(DatagramSocket delegate) Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering on a specific DatagramSocket.
      MultiplexingDatagramSocket(DatagramSocket delegate, boolean persistent) Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering on a specific DatagramSocket.
      MultiplexingDatagramSocket(int port) Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering and binds it to the specified port on the local host machine.
      MultiplexingDatagramSocket(int port, boolean persistent) Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering and binds it to the specified port on the local host machine.
      MultiplexingDatagramSocket(int port, InetAddress laddr) Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering, bound to the specified local address.
      MultiplexingDatagramSocket(int port, InetAddress laddr, boolean persistent) Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering, bound to the specified local address.
      MultiplexingDatagramSocket(SocketAddress bindaddr) Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering, bound to the specified local socket address.
      MultiplexingDatagramSocket(SocketAddress bindaddr, boolean persistent) Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering, bound to the specified local socket address.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      int getSoTimeout() Retrieves setting for SO_TIMEOUT.
      void setSoTimeout(int timeout) Enables/disables SO_TIMEOUT with the specified timeout, in milliseconds.
      MultiplexedDatagramSocket getSocket(DatagramPacketFilter filter) Gets a MultiplexedDatagramSocket which filters DatagramPackets away from this DatagramSocket using a specific DatagramPacketFilter.
      MultiplexedDatagramSocket getSocket(DatagramPacketFilter filter, boolean create) Gets a MultiplexedDatagramSocket which filters DatagramPackets away from this DatagramSocket using a specific DatagramPacketFilter.
      void receive(DatagramPacket p) Receives a datagram packet from this socket.
      void setReceiveBufferSize(int receiveBufferSize) Sets the SO_RCVBUF option to the specified value for this DatagramSocket.
      • Methods inherited from class org.ice4j.socket.SafeCloseDatagramSocket

        close
      • Methods inherited from class org.ice4j.socket.DelegatingDatagramSocket

        bind, connect, connect, disconnect, getBroadcast, getChannel, getInetAddress, getLocalAddress, getLocalPort, getLocalSocketAddress, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getTrafficClass, isBound, isClosed, isConnected, send, setBroadcast, setDefaultDelegateFactory, setDefaultReceiveBufferSize, setReuseAddress, setSendBufferSize, setTrafficClass
      • Methods inherited from class java.net.DatagramSocket

        bind, close, connect, disconnect, getBroadcast, getChannel, getInetAddress, getLocalAddress, getLocalPort, getLocalSocketAddress, getOption, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoTimeout, getTrafficClass, isBound, isClosed, isConnected, receive, send, setBroadcast, setDatagramSocketImplFactory, setOption, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSoTimeout, setTrafficClass, supportedOptions
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MultiplexingDatagramSocket

        MultiplexingDatagramSocket()
        Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering and binds it to any available port on the local host machine.
      • MultiplexingDatagramSocket

        MultiplexingDatagramSocket(boolean persistent)
        Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering and binds it to any available port on the local host machine.
        Parameters:
        persistent - whether this socket should be kept open after all of its MultiplexedDatagramSockets are closed.
      • MultiplexingDatagramSocket

        MultiplexingDatagramSocket(DatagramSocket delegate)
        Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering on a specific DatagramSocket.
        Parameters:
        delegate - the DatagramSocket on which DatagramPacket filtering is to be enabled by the new instance
      • MultiplexingDatagramSocket

        MultiplexingDatagramSocket(DatagramSocket delegate, boolean persistent)
        Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering on a specific DatagramSocket.
        Parameters:
        delegate - the DatagramSocket on which DatagramPacket filtering is to be enabled by the new instance
        persistent - whether this socket should be kept open after all of its MultiplexedDatagramSockets are closed.
      • MultiplexingDatagramSocket

        MultiplexingDatagramSocket(int port)
        Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering and binds it to the specified port on the local host machine.
        Parameters:
        port - the port to bind the new socket to
      • MultiplexingDatagramSocket

        MultiplexingDatagramSocket(int port, boolean persistent)
        Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering and binds it to the specified port on the local host machine.
        Parameters:
        port - the port to bind the new socket to
        persistent - whether this socket should be kept open after all of its MultiplexedDatagramSockets are closed.
      • MultiplexingDatagramSocket

        MultiplexingDatagramSocket(int port, InetAddress laddr)
        Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering, bound to the specified local address.
        Parameters:
        port - the local port to bind the new socket to
        laddr - the local address to bind the new socket to
      • MultiplexingDatagramSocket

        MultiplexingDatagramSocket(int port, InetAddress laddr, boolean persistent)
        Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering, bound to the specified local address.
        Parameters:
        port - the local port to bind the new socket to
        laddr - the local address to bind the new socket to
        persistent - whether this socket should be kept open after all of its MultiplexedDatagramSockets are closed.
      • MultiplexingDatagramSocket

        MultiplexingDatagramSocket(SocketAddress bindaddr)
        Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering, bound to the specified local socket address.
        Parameters:
        bindaddr - local socket address to bind, or null for an unbound socket
      • MultiplexingDatagramSocket

        MultiplexingDatagramSocket(SocketAddress bindaddr, boolean persistent)
        Initializes a new MultiplexingDatagramSocket instance which is to enable DatagramPacket filtering, bound to the specified local socket address.
        Parameters:
        bindaddr - local socket address to bind, or null for an unbound socket
        persistent - whether this socket should be kept open after all of its MultiplexedDatagramSockets are closed.
    • Method Detail

      • getSoTimeout

         int getSoTimeout()

        Retrieves setting for SO_TIMEOUT. Zero returned implies that the option is disabled (i.e., timeout of infinity).

      • setSoTimeout

         void setSoTimeout(int timeout)

        Enables/disables SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a call to #receive(DatagramPacket) for this DatagramSocket will block for only this amount of time. If the timeout expires, a SocketTimeoutException is raised, though the DatagramSocket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be greater than zero. A timeout of zero is interpreted as an infinite timeout.

      • getSocket

         MultiplexedDatagramSocket getSocket(DatagramPacketFilter filter)

        Gets a MultiplexedDatagramSocket which filters DatagramPackets away from this DatagramSocket using a specific DatagramPacketFilter. If such a MultiplexedDatagramSocket does not exist in this instance, it is created.

        Parameters:
        filter - the DatagramPacketFilter to get a MultiplexedDatagramSocket for
      • getSocket

         MultiplexedDatagramSocket getSocket(DatagramPacketFilter filter, boolean create)

        Gets a MultiplexedDatagramSocket which filters DatagramPackets away from this DatagramSocket using a specific DatagramPacketFilter. If create is true and such a MultiplexedDatagramSocket does not exist in this instance, it is created.

        Parameters:
        filter - the DatagramPacketFilter to get a MultiplexedDatagramSocket for
        create - whether or not to create a MultiplexedDatagramSocket if this instance does not already have a socket for the given filter.
      • receive

         void receive(DatagramPacket p)

        Receives a datagram packet from this socket. The DatagramPackets returned by this method do not match any of the DatagramPacketFilters of the MultiplexedDatagramSockets associated with this instance at the time of their receipt. When this method returns, the DatagramPacket's buffer is filled with the data received. The datagram packet also contains the sender's IP address, and the port number on the sender's machine.

        This method blocks until a datagram is received. The length field of the datagram packet object contains the length of the received message. If the message is longer than the packet's length, the message is truncated.

        Parameters:
        p - the DatagramPacket into which to place the incoming data
      • setReceiveBufferSize

         void setReceiveBufferSize(int receiveBufferSize)

        Sets the SO_RCVBUF option to the specified value for this DatagramSocket. The SO_RCVBUF option is used by the network implementation as a hint to size the underlying network I/O buffers. The SO_RCVBUF setting may also be used by the network implementation to determine the maximum size of the packet that can be received on this socket.

        Because SO_RCVBUF is a hint, applications that want to verify what size the buffers were set to should call #getReceiveBufferSize().