Package jnr.unixsocket
Class UnixDatagramSocket
- java.lang.Object
-
- java.net.DatagramSocket
-
- jnr.unixsocket.UnixDatagramSocket
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class UnixDatagramSocket extends 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(SocketAddress local)
Binds this UnixDatagramSocket to a specific AF_UNIX address.void
close()
void
connect(InetAddress addr, int port)
void
connect(SocketAddress addr)
void
disconnect()
DatagramChannel
getChannel()
Credentials
getCredentials()
Retrieves the credentials for this UNIX socket.InetAddress
getInetAddress()
Returns the address to which this socket is connected (NOT implemented).SocketAddress
getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to.int
getReceiveBufferSize()
SocketAddress
getRemoteSocketAddress()
Returns the address of the endpoint this socket is connected to, ornull
if it is unconnected.int
getSendBufferSize()
int
getSoTimeout()
boolean
isBound()
boolean
isClosed()
boolean
isConnected()
void
receive(DatagramPacket p)
Receives a datagram packet from this socket (NOT implemented).void
send(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
-
-
-
-
Constructor Detail
-
UnixDatagramSocket
public UnixDatagramSocket() throws SocketException
Constructs a new unbound instance.- Throws:
SocketException
- if the socket could not be created.
-
-
Method Detail
-
bind
public void bind(SocketAddress local) throws 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 classDatagramSocket
- Parameters:
local
- TheUnixSocketAddress
to 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:
disconnect
in classDatagramSocket
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classDatagramSocket
-
connect
public void connect(SocketAddress addr) throws SocketException
- Overrides:
connect
in classDatagramSocket
- Throws:
SocketException
-
connect
public void connect(InetAddress addr, int port)
- Overrides:
connect
in classDatagramSocket
-
getChannel
public DatagramChannel getChannel()
- Overrides:
getChannel
in classDatagramSocket
-
getInetAddress
public InetAddress 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:
getInetAddress
in classDatagramSocket
- Returns:
null
always.
-
getLocalSocketAddress
public SocketAddress getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to.- Overrides:
getLocalSocketAddress
in classDatagramSocket
- Returns:
- a
SocketAddress
representing the local endpoint of this socket, ornull
if it is closed or not bound. A non-null return value is always of typeUnixSocketAddress
- See Also:
bind(SocketAddress)
-
getRemoteSocketAddress
public SocketAddress getRemoteSocketAddress()
Returns the address of the endpoint this socket is connected to, ornull
if it is unconnected.- Overrides:
getRemoteSocketAddress
in classDatagramSocket
- Returns:
- a
SocketAddress
representing the remote endpoint of this socket, ornull
if it is not connected. A non-null return value is always of typeUnixSocketAddress
-
isBound
public boolean isBound()
- Overrides:
isBound
in classDatagramSocket
-
isClosed
public boolean isClosed()
- Overrides:
isClosed
in classDatagramSocket
-
isConnected
public boolean isConnected()
- Overrides:
isConnected
in classDatagramSocket
-
getCredentials
public final Credentials getCredentials() throws 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:
UnsupportedOperationException
- if the underlying socket library doesn't support the SO_PEERCRED optionSocketException
- if fetching the socket option failed.
-
getReceiveBufferSize
public int getReceiveBufferSize() throws SocketException
- Overrides:
getReceiveBufferSize
in classDatagramSocket
- Throws:
SocketException
-
getSendBufferSize
public int getSendBufferSize() throws SocketException
- Overrides:
getSendBufferSize
in classDatagramSocket
- Throws:
SocketException
-
getSoTimeout
public int getSoTimeout() throws SocketException
- Overrides:
getSoTimeout
in classDatagramSocket
- Throws:
SocketException
-
setReceiveBufferSize
public void setReceiveBufferSize(int size) throws SocketException
- Overrides:
setReceiveBufferSize
in classDatagramSocket
- Throws:
SocketException
-
setSendBufferSize
public void setSendBufferSize(int size) throws SocketException
- Overrides:
setSendBufferSize
in classDatagramSocket
- Throws:
SocketException
-
setSoTimeout
public void setSoTimeout(int timeout) throws SocketException
- Overrides:
setSoTimeout
in classDatagramSocket
- Throws:
SocketException
-
send
public void send(DatagramPacket p) throws 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 classDatagramSocket
- Throws:
UnsupportedOperationException
- always.IOException
- See Also:
DatagramPacket
,DatagramSocket.send(java.net.DatagramPacket)
-
receive
public void receive(DatagramPacket p) throws 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 classDatagramSocket
- Throws:
UnsupportedOperationException
- always.IOException
- See Also:
DatagramPacket
,DatagramSocket.receive(java.net.DatagramPacket)
-
-