Class UnixDatagramSocket
java.lang.Object
java.net.DatagramSocket
jnr.unixsocket.UnixDatagramSocket
- All Implemented Interfaces:
Closeable, AutoCloseable
A SOCK_DGRAM variant of an AF_UNIX socket.
This specializaton of DatagramSocket delegates
most of it's funtionality to the corresponding
UnixDatagramChannel.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new unbound instance.UnixDatagramSocket(UnixDatagramChannel channel) Constructs a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidbind(SocketAddress local) Binds this UnixDatagramSocket to a specific AF_UNIX address.voidclose()voidconnect(InetAddress addr, int port) voidconnect(SocketAddress addr) voidfinal CredentialsRetrieves the credentials for this UNIX socket.Returns the address to which this socket is connected (NOT implemented).Returns the address of the endpoint this socket is bound to.intReturns the address of the endpoint this socket is connected to, ornullif it is unconnected.intintprivate voidignore()booleanisBound()booleanisClosed()booleanvoidReceives a datagram packet from this socket (NOT implemented).voidSends a datagram packet from this socket (NOT implemented).voidsetReceiveBufferSize(int size) voidsetSendBufferSize(int size) voidsetSoTimeout(int timeout) Methods inherited from class DatagramSocket
getBroadcast, getLocalAddress, getLocalPort, getPort, getReuseAddress, getTrafficClass, setBroadcast, setDatagramSocketImplFactory, setReuseAddress, setTrafficClass
-
Field Details
-
chan
-
closed
-
-
Constructor Details
-
UnixDatagramSocket
UnixDatagramSocket(UnixDatagramChannel channel) throws SocketException Constructs a new instance.- Parameters:
channel- The channel to use.- Throws:
SocketException- if the socket could not be created.
-
UnixDatagramSocket
Constructs a new unbound instance.- Throws:
SocketException- if the socket could not be created.
-
-
Method Details
-
bind
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:
bindin classDatagramSocket- Parameters:
local- TheUnixSocketAddressto bind to.- Throws:
SocketException- if any error happens during the bind, or if the socket is already bound.UnsupportedAddressTypeException- if addr is a SocketAddress subclass not supported by this socket.
-
disconnect
public void disconnect()- Overrides:
disconnectin classDatagramSocket
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classDatagramSocket
-
connect
- Overrides:
connectin classDatagramSocket- Throws:
SocketException
-
connect
- Overrides:
connectin classDatagramSocket
-
getChannel
- Overrides:
getChannelin classDatagramSocket
-
getInetAddress
Returns the address to which this socket is connected (NOT implemented). Since AF_UNIX sockets can not have an InetAddress, this returns alwaysnull. UsegetRemoteSocketAddress()instead, which always returns aUnixSocketAddress.- Overrides:
getInetAddressin classDatagramSocket- Returns:
nullalways.
-
getLocalSocketAddress
Returns the address of the endpoint this socket is bound to.- Overrides:
getLocalSocketAddressin classDatagramSocket- Returns:
- a
SocketAddressrepresenting the local endpoint of this socket, ornullif it is closed or not bound. A non-null return value is always of typeUnixSocketAddress - See Also:
-
getRemoteSocketAddress
Returns the address of the endpoint this socket is connected to, ornullif it is unconnected.- Overrides:
getRemoteSocketAddressin classDatagramSocket- Returns:
- a
SocketAddressrepresenting the remote endpoint of this socket, ornullif it is not connected. A non-null return value is always of typeUnixSocketAddress
-
isBound
public boolean isBound()- Overrides:
isBoundin classDatagramSocket
-
isClosed
public boolean isClosed()- Overrides:
isClosedin classDatagramSocket
-
isConnected
public boolean isConnected()- Overrides:
isConnectedin classDatagramSocket
-
getCredentials
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:
UnsupportedOperationException- if the underlying socket library doesn't support the SO_PEERCRED optionSocketException- if fetching the socket option failed.
-
getReceiveBufferSize
- Overrides:
getReceiveBufferSizein classDatagramSocket- Throws:
SocketException
-
getSendBufferSize
- Overrides:
getSendBufferSizein classDatagramSocket- Throws:
SocketException
-
getSoTimeout
- Overrides:
getSoTimeoutin classDatagramSocket- Throws:
SocketException
-
setReceiveBufferSize
- Overrides:
setReceiveBufferSizein classDatagramSocket- Throws:
SocketException
-
setSendBufferSize
- Overrides:
setSendBufferSizein classDatagramSocket- Throws:
SocketException
-
setSoTimeout
- Overrides:
setSoTimeoutin classDatagramSocket- Throws:
SocketException
-
send
Sends a datagram packet from this socket (NOT implemented). Unfortunately,DatagramPacketis final and can not deal with AF_UNIX addresses. Therefore, this functionality was omitted.- Overrides:
sendin classDatagramSocket- Throws:
UnsupportedOperationException- always.IOException- See Also:
-
receive
Receives a datagram packet from this socket (NOT implemented). Unfortunately,DatagramPacketis final and can not deal with AF_UNIX addresses. Therefore, this functionality was omitted.- Overrides:
receivein classDatagramSocket- Throws:
UnsupportedOperationException- always.IOException- See Also:
-
ignore
private void ignore()
-