Top Description Fields Constructors Methods
jnr.unixsocket

public Class UnixDatagramSocket

extends DatagramSocket
Class Inheritance
Imports
java.io.IOException, java.net.InetAddress, .SocketAddress, .SocketException, .DatagramPacket, .DatagramSocket, java.nio.channels.DatagramChannel, .UnsupportedAddressTypeException, java.util.concurrent.atomic.AtomicBoolean

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

Modifier and TypeField and Description
private final UnixDatagramChannel
private final AtomicBoolean

Constructor Summary

AccessConstructor and Description
pack-priv
UnixDatagramSocket(final UnixDatagramChannel
The channel to use.
channel
)

Constructs a new instance.

public
UnixDatagramSocket()

Constructs a new unbound instance.

Method Summary

Modifier and TypeMethod and Description
public void
bind(final SocketAddress
The UnixSocketAddress to bind to.
local
)

Overrides java.net.DatagramSocket.bind.

Binds this UnixDatagramSocket to a specific AF_UNIX address.
public synchronized void
close()

Overrides java.net.DatagramSocket.close.

Implements java.io.Closeable.close.

Closes this datagram socket.
public void
connect(SocketAddress
The remote address.
addr
)

Overrides java.net.DatagramSocket.connect.

Connects this socket to a remote socket address (IP address + port number).
public void
connect(InetAddress
the remote address for the socket
addr
,
int
the remote port for the socket.
port
)

Overrides java.net.DatagramSocket.connect.

Connects the socket to a remote address for this socket.
public synchronized void
disconnect()

Overrides java.net.DatagramSocket.disconnect.

Disconnects the socket.
public DatagramChannel
getChannel()

Overrides java.net.DatagramSocket.getChannel.

Returns the unique java.nio.channels.DatagramChannel object associated with this datagram socket, if any.
public final Credentials

Returns:

the credentials of the remote; null if not connected
getCredentials
()

Retrieves the credentials for this UNIX socket.

public InetAddress

Returns:

null always.
getInetAddress
()

Overrides java.net.DatagramSocket.getInetAddress.

Returns the address to which this socket is connected (NOT implemented).
public SocketAddress

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
getLocalSocketAddress
()

Overrides java.net.DatagramSocket.getLocalSocketAddress.

Returns the address of the endpoint this socket is bound to.
public int
getReceiveBufferSize()

Overrides java.net.DatagramSocket.getReceiveBufferSize.

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.
public SocketAddress

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
getRemoteSocketAddress
()

Overrides java.net.DatagramSocket.getRemoteSocketAddress.

Returns the address of the endpoint this socket is connected to, or null if it is unconnected.
public int
getSendBufferSize()

Overrides java.net.DatagramSocket.getSendBufferSize.

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.
public int
getSoTimeout()

Overrides java.net.DatagramSocket.getSoTimeout.

Retrieve setting for SO_TIMEOUT.
private void
public boolean
isBound()

Overrides java.net.DatagramSocket.isBound.

Returns the binding state of the socket.
public boolean
isClosed()

Overrides java.net.DatagramSocket.isClosed.

Returns whether the socket is closed or not.
public boolean
isConnected()

Overrides java.net.DatagramSocket.isConnected.

Returns the connection state of the socket.
public synchronized void
receive(DatagramPacket
the DatagramPacket into which to place the incoming data.
p
)

Overrides java.net.DatagramSocket.receive.

Receives a datagram packet from this socket (NOT implemented).
public void
send(DatagramPacket
the DatagramPacket to be sent.
p
)

Overrides java.net.DatagramSocket.send.

Sends a datagram packet from this socket (NOT implemented).
public void
setReceiveBufferSize(int
the size to which to set the receive buffer size, in bytes. This value must be greater than 0.
size
)

Overrides java.net.DatagramSocket.setReceiveBufferSize.

Sets the SO_RCVBUF option to the specified value for this DatagramSocket.
public void
setSendBufferSize(int
the size to which to set the send buffer size, in bytes. This value must be greater than 0.
size
)

Overrides java.net.DatagramSocket.setSendBufferSize.

Sets the SO_SNDBUF option to the specified value for this DatagramSocket.
public void
setSoTimeout(int
the specified timeout in milliseconds.
timeout
)

Overrides java.net.DatagramSocket.setSoTimeout.

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
Inherited from java.net.DatagramSocket:
getBroadcastgetLocalAddressgetLocalPortgetOptiongetPortgetReuseAddressgetTrafficClassjoinGroupleaveGroupsetBroadcastsetDatagramSocketImplFactorysetOptionsetReuseAddresssetTrafficClasssupportedOptions

Field Detail

chanback to summary
private final UnixDatagramChannel chan
closedback to summary
private final AtomicBoolean closed

Constructor Detail

UnixDatagramSocketback to summary
pack-priv UnixDatagramSocket(final UnixDatagramChannel channel) throws SocketException

Constructs a new instance.

Parameters
channel:UnixDatagramChannel

The channel to use.

Exceptions
SocketException:
if the socket could not be created.
UnixDatagramSocketback to summary
public UnixDatagramSocket() throws SocketException

Constructs a new unbound instance.

Exceptions
SocketException:
if the socket could not be created.

Method Detail

bindback to summary
public void bind(final SocketAddress local) throws SocketException

Overrides java.net.DatagramSocket.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.

Parameters
local:SocketAddress

The UnixSocketAddress to bind to.

Annotations
@Override
Exceptions
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.
closeback to summary
public synchronized void close()

Overrides java.net.DatagramSocket.close.

Implements java.io.Closeable.close.

Doc from java.net.DatagramSocket.close.

Closes this datagram socket.

Any thread currently blocked in receive upon this socket will throw a SocketException.

If this socket has an associated channel then the channel is closed as well.

Annotations
@Override
connectback to summary
public void connect(SocketAddress addr) throws SocketException

Overrides java.net.DatagramSocket.connect.

Doc from java.net.DatagramSocket.connect.

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

If given an InetSocketAddress, this method behaves as if invoking connect(InetAddress,int) with the given socket addresses IP address and port number, except that the SocketException that may be raised is not wrapped in an UncheckedIOException. Datagrams in the socket's socket receive buffer, which have not been received before invoking this method, may be discarded.

Parameters
addr:SocketAddress

The remote address.

Annotations
@Override
Exceptions
SocketException:
if the connect fails
connectback to summary
public void connect(InetAddress addr, int port)

Overrides java.net.DatagramSocket.connect.

Doc from java.net.DatagramSocket.connect.

Connects the socket to a remote address for this socket. When a socket is connected to a remote address, packets may only be sent to or received from that address. By default a datagram socket is not connected. If the socket is already closed, then this method has no effect.

If this socket is not bound then this method will first cause the socket to be bound to an address that is assigned automatically, as if invoking the bind method with a parameter of null. If the remote destination to which the socket is connected does not exist, or is otherwise unreachable, and if an ICMP destination unreachable packet has been received for that address, then a subsequent call to send or receive may throw a PortUnreachableException. Note, there is no guarantee that the exception will be thrown.

If a security manager has been installed then it is invoked to check access to the remote address. Specifically, if the given address is a multicast address, the security manager's checkMulticast method is invoked with the given address. Otherwise, the security manager's checkConnect and checkAccept methods are invoked, with the given address and port, to verify that datagrams are permitted to be sent and received respectively.

Care should be taken to ensure that a connected datagram socket is not shared with untrusted code. When a socket is connected, receive and send will not perform any security checks on incoming and outgoing packets, other than matching the packet's and the socket's address and port. On a send operation, if the packet's address is set and the packet's address and the socket's address do not match, an IllegalArgumentException will be thrown. A socket connected to a multicast address may only be used to send packets. Datagrams in the socket's socket receive buffer, which have not been received before invoking this method, may be discarded.

Parameters
addr:InetAddress

the remote address for the socket

port:int

the remote port for the socket.

Annotations
@Override
disconnectback to summary
public synchronized void disconnect()

Overrides java.net.DatagramSocket.disconnect.

Doc from java.net.DatagramSocket.disconnect.

Disconnects the socket. If the socket is closed or not connected, then this method has no effect.

Annotations
@Override
getChannelback to summary
public DatagramChannel getChannel()

Overrides java.net.DatagramSocket.getChannel.

Doc from java.net.DatagramSocket.getChannel.

Returns the unique java.nio.channels.DatagramChannel object associated with this datagram socket, if any.

A datagram socket will have a channel if, and only if, the channel itself was created via the DatagramChannel.open method.

Returns:DatagramChannel

the datagram channel associated with this datagram socket, or null if this socket was not created for a channel

Annotations
@Override
getCredentialsback to summary
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:Credentials

the credentials of the remote; null if not connected

Exceptions
SocketException:
if fetching the socket option failed.
UnsupportedOperationException:
if the underlying socket library doesn't support the SO_PEERCRED option
getInetAddressback to summary
public InetAddress getInetAddress()

Overrides java.net.DatagramSocket.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.

Returns:InetAddress

null always.

Annotations
@Override
getLocalSocketAddressback to summary
public SocketAddress getLocalSocketAddress()

Overrides java.net.DatagramSocket.getLocalSocketAddress.

Returns the address of the endpoint this socket is bound to.

Returns:SocketAddress

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

Annotations
@Override
See Also
bind(SocketAddress)
getReceiveBufferSizeback to summary
public int getReceiveBufferSize() throws SocketException

Overrides java.net.DatagramSocket.getReceiveBufferSize.

Doc from java.net.DatagramSocket.getReceiveBufferSize.

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:int

the value of the SO_RCVBUF option for this DatagramSocket

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as an UDP error.
getRemoteSocketAddressback to summary
public SocketAddress getRemoteSocketAddress()

Overrides java.net.DatagramSocket.getRemoteSocketAddress.

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

Returns:SocketAddress

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

Annotations
@Override
getSendBufferSizeback to summary
public int getSendBufferSize() throws SocketException

Overrides java.net.DatagramSocket.getSendBufferSize.

Doc from java.net.DatagramSocket.getSendBufferSize.

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.

Returns:int

the value of the SO_SNDBUF option for this DatagramSocket

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as an UDP error.
getSoTimeoutback to summary
public int getSoTimeout() throws SocketException

Overrides java.net.DatagramSocket.getSoTimeout.

Doc from java.net.DatagramSocket.getSoTimeout.

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

Returns:int

the setting for SO_TIMEOUT

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as an UDP error.
ignoreback to summary
private void ignore()
isBoundback to summary
public boolean isBound()

Overrides java.net.DatagramSocket.isBound.

Doc from java.net.DatagramSocket.isBound.

Returns the binding state of the socket.

If the socket was bound prior to being closed, then this method will continue to return true after the socket is closed.

Returns:boolean

true if the socket successfully bound to an address

Annotations
@Override
isClosedback to summary
public boolean isClosed()

Overrides java.net.DatagramSocket.isClosed.

Doc from java.net.DatagramSocket.isClosed.

Returns whether the socket is closed or not.

Returns:boolean

true if the socket has been closed

Annotations
@Override
isConnectedback to summary
public boolean isConnected()

Overrides java.net.DatagramSocket.isConnected.

Doc from java.net.DatagramSocket.isConnected.

Returns the connection state of the socket.

If the socket was connected prior to being closed, then this method will continue to return true after the socket is closed.

Returns:boolean

true if the socket successfully connected to a server

Annotations
@Override
receiveback to summary
public synchronized void receive(DatagramPacket p) throws IOException

Overrides java.net.DatagramSocket.receive.

Receives a datagram packet from this socket (NOT implemented). Unfortunately, java.net.DatagramPacket is final and can not deal with AF_UNIX addresses. Therefore, this functionality was omitted.

Parameters
p:DatagramPacket

Doc from java.net.DatagramSocket.receive.

the DatagramPacket into which to place the incoming data.

Annotations
@Override
Exceptions
IOException:

Doc from java.net.DatagramSocket.receive.

if an I/O error occurs.

UnsupportedOperationException:
always.
See Also
java.net.DatagramPacket, java.net.DatagramSocket#receive
sendback to summary
public void send(DatagramPacket p) throws IOException

Overrides java.net.DatagramSocket.send.

Sends a datagram packet from this socket (NOT implemented). Unfortunately, java.net.DatagramPacket is final and can not deal with AF_UNIX addresses. Therefore, this functionality was omitted.

Parameters
p:DatagramPacket

Doc from java.net.DatagramSocket.send.

the DatagramPacket to be sent.

Annotations
@Override
Exceptions
IOException:

Doc from java.net.DatagramSocket.send.

if an I/O error occurs.

UnsupportedOperationException:
always.
See Also
java.net.DatagramPacket, java.net.DatagramSocket#send
setReceiveBufferSizeback to summary
public void setReceiveBufferSize(int size) throws SocketException

Overrides java.net.DatagramSocket.setReceiveBufferSize.

Doc from java.net.DatagramSocket.setReceiveBufferSize.

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().

Increasing SO_RCVBUF may allow the network implementation to buffer multiple packets when packets arrive faster than are being received using receive(DatagramPacket).

Note

It is implementation specific if a packet larger than SO_RCVBUF can be received.

Parameters
size:int

the size to which to set the receive buffer size, in bytes. This value must be greater than 0.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as an UDP error.
setSendBufferSizeback to summary
public void setSendBufferSize(int size) throws SocketException

Overrides java.net.DatagramSocket.setSendBufferSize.

Doc from java.net.DatagramSocket.setSendBufferSize.

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

As SO_SNDBUF is a hint, applications that want to verify what size the buffer is should call getSendBufferSize().

Increasing the buffer size may allow multiple outgoing packets to be queued by the network implementation when the send rate is high.

Note

If send(DatagramPacket) is used to send a DatagramPacket that is larger than the setting of SO_SNDBUF then it is implementation specific if the packet is sent or discarded.

Parameters
size:int

the size to which to set the send buffer size, in bytes. This value must be greater than 0.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as an UDP error.
setSoTimeoutback to summary
public void setSoTimeout(int timeout) throws SocketException

Overrides java.net.DatagramSocket.setSoTimeout.

Doc from java.net.DatagramSocket.setSoTimeout.

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a positive timeout value, a call to receive() for this DatagramSocket will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the DatagramSocket is still valid. A timeout of zero is interpreted as an infinite timeout. The option must be enabled prior to entering the blocking operation to have effect.

Parameters
timeout:int

the specified timeout in milliseconds.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as an UDP error.