Class UnixDatagramSocket

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

    public class UnixDatagramSocket
    extends java.net.DatagramSocket
    A SOCK_DGRAM variant of an AF_UNIX socket. This specializaton of DatagramSocket delegates most of it's funtionality to the corresponding UnixDatagramChannel.
    • Constructor Summary

      Constructors 
      Constructor Description
      UnixDatagramSocket()
      Constructs a new unbound instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void bind​(java.net.SocketAddress local)
      Binds this UnixDatagramSocket to a specific AF_UNIX address.
      void close()  
      void connect​(java.net.InetAddress addr, int port)  
      void connect​(java.net.SocketAddress addr)  
      void disconnect()  
      java.nio.channels.DatagramChannel getChannel()  
      Credentials getCredentials()
      Retrieves the credentials for this UNIX socket.
      java.net.InetAddress getInetAddress()
      Returns the address to which this socket is connected (NOT implemented).
      java.net.SocketAddress getLocalSocketAddress()
      Returns the address of the endpoint this socket is bound to.
      int getReceiveBufferSize()  
      java.net.SocketAddress getRemoteSocketAddress()
      Returns the address of the endpoint this socket is connected to, or null if it is unconnected.
      int getSendBufferSize()  
      int getSoTimeout()  
      boolean isBound()  
      boolean isClosed()  
      boolean isConnected()  
      void receive​(java.net.DatagramPacket p)
      Receives a datagram packet from this socket (NOT implemented).
      void send​(java.net.DatagramPacket p)
      Sends a datagram packet from this socket (NOT implemented).
      void setReceiveBufferSize​(int size)  
      void setSendBufferSize​(int size)  
      void setSoTimeout​(int timeout)  
      • Methods inherited from class java.net.DatagramSocket

        getBroadcast, getLocalAddress, getLocalPort, getOption, getPort, getReuseAddress, getTrafficClass, setBroadcast, setDatagramSocketImplFactory, setOption, setReuseAddress, setTrafficClass, supportedOptions
      • Methods inherited from class java.lang.Object

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

      • UnixDatagramSocket

        public UnixDatagramSocket()
                           throws java.net.SocketException
        Constructs a new unbound instance.
        Throws:
        java.net.SocketException - if the socket could not be created.
    • Method Detail

      • bind

        public void bind​(java.net.SocketAddress local)
                  throws java.net.SocketException
        Binds this UnixDatagramSocket to a specific AF_UNIX address.

        If the address is null, then on Linux, an autobind will be performed, which will bind this socket in Linux' abstract namespace on a unique path, chosen by the system. On all other platforms, A temporary path in the regular filesystem will be chosen.

        Overrides:
        bind in class java.net.DatagramSocket
        Parameters:
        local - The UnixSocketAddress to bind to.
        Throws:
        java.net.SocketException - if any error happens during the bind, or if the socket is already bound.
        java.nio.channels.UnsupportedAddressTypeException - if addr is a SocketAddress subclass not supported by this socket.
      • disconnect

        public void disconnect()
        Overrides:
        disconnect in class java.net.DatagramSocket
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.net.DatagramSocket
      • connect

        public void connect​(java.net.SocketAddress addr)
                     throws java.net.SocketException
        Overrides:
        connect in class java.net.DatagramSocket
        Throws:
        java.net.SocketException
      • connect

        public void connect​(java.net.InetAddress addr,
                            int port)
        Overrides:
        connect in class java.net.DatagramSocket
      • getChannel

        public java.nio.channels.DatagramChannel getChannel()
        Overrides:
        getChannel in class java.net.DatagramSocket
      • getInetAddress

        public java.net.InetAddress getInetAddress()
        Returns the address to which this socket is connected (NOT implemented). Since AF_UNIX sockets can not have an InetAddress, this returns always null. Use getRemoteSocketAddress() instead, which always returns a UnixSocketAddress.
        Overrides:
        getInetAddress in class java.net.DatagramSocket
        Returns:
        null always.
      • getLocalSocketAddress

        public java.net.SocketAddress getLocalSocketAddress()
        Returns the address of the endpoint this socket is bound to.
        Overrides:
        getLocalSocketAddress in class java.net.DatagramSocket
        Returns:
        a SocketAddress representing the local endpoint of this socket, or null if it is closed or not bound. A non-null return value is always of type UnixSocketAddress
        See Also:
        bind(SocketAddress)
      • getRemoteSocketAddress

        public java.net.SocketAddress getRemoteSocketAddress()
        Returns the address of the endpoint this socket is connected to, or null if it is unconnected.
        Overrides:
        getRemoteSocketAddress in class java.net.DatagramSocket
        Returns:
        a SocketAddress representing the remote endpoint of this socket, or null if it is not connected. A non-null return value is always of type UnixSocketAddress
      • isBound

        public boolean isBound()
        Overrides:
        isBound in class java.net.DatagramSocket
      • isClosed

        public boolean isClosed()
        Overrides:
        isClosed in class java.net.DatagramSocket
      • isConnected

        public boolean isConnected()
        Overrides:
        isConnected in class java.net.DatagramSocket
      • getCredentials

        public final Credentials getCredentials()
                                         throws java.net.SocketException
        Retrieves the credentials for this UNIX socket. Clients calling this method will receive the server's credentials, and servers will receive the client's credentials. User ID, group ID, and PID are supplied. See man unix 7; SCM_CREDENTIALS
        Returns:
        the credentials of the remote; null if not connected
        Throws:
        java.lang.UnsupportedOperationException - if the underlying socket library doesn't support the SO_PEERCRED option
        java.net.SocketException - if fetching the socket option failed.
      • getReceiveBufferSize

        public int getReceiveBufferSize()
                                 throws java.net.SocketException
        Overrides:
        getReceiveBufferSize in class java.net.DatagramSocket
        Throws:
        java.net.SocketException
      • getSendBufferSize

        public int getSendBufferSize()
                              throws java.net.SocketException
        Overrides:
        getSendBufferSize in class java.net.DatagramSocket
        Throws:
        java.net.SocketException
      • getSoTimeout

        public int getSoTimeout()
                         throws java.net.SocketException
        Overrides:
        getSoTimeout in class java.net.DatagramSocket
        Throws:
        java.net.SocketException
      • setReceiveBufferSize

        public void setReceiveBufferSize​(int size)
                                  throws java.net.SocketException
        Overrides:
        setReceiveBufferSize in class java.net.DatagramSocket
        Throws:
        java.net.SocketException
      • setSendBufferSize

        public void setSendBufferSize​(int size)
                               throws java.net.SocketException
        Overrides:
        setSendBufferSize in class java.net.DatagramSocket
        Throws:
        java.net.SocketException
      • setSoTimeout

        public void setSoTimeout​(int timeout)
                          throws java.net.SocketException
        Overrides:
        setSoTimeout in class java.net.DatagramSocket
        Throws:
        java.net.SocketException
      • send

        public void send​(java.net.DatagramPacket p)
                  throws java.io.IOException
        Sends a datagram packet from this socket (NOT implemented). Unfortunately, DatagramPacket is final and can not deal with AF_UNIX addresses. Therefore, this functionality was omitted.
        Overrides:
        send in class java.net.DatagramSocket
        Throws:
        java.lang.UnsupportedOperationException - always.
        java.io.IOException
        See Also:
        DatagramPacket, DatagramSocket.send(java.net.DatagramPacket)
      • receive

        public void receive​(java.net.DatagramPacket p)
                     throws java.io.IOException
        Receives a datagram packet from this socket (NOT implemented). Unfortunately, DatagramPacket is final and can not deal with AF_UNIX addresses. Therefore, this functionality was omitted.
        Overrides:
        receive in class java.net.DatagramSocket
        Throws:
        java.lang.UnsupportedOperationException - always.
        java.io.IOException
        See Also:
        DatagramPacket, DatagramSocket.receive(java.net.DatagramPacket)