APIdia Launch Partner
Top Description Fields Constructors Methods
java.net

public abstract Class DatagramSocketImpl

extends Object
implements SocketOptions
Class Inheritance
All Implemented Interfaces
java.net.SocketOptions
Imports
java.io.FileDescriptor, .IOException, .UncheckedIOException, java.util.Objects, .Set

Abstract datagram and multicast socket implementation base class.
Author
Pavani Diwanji
Since
1.1

Field Summary

Modifier and TypeField and Description
protected FileDescriptor
fd

The file descriptor object.

protected int
localPort

The local port number.

Constructor Summary

AccessConstructor and Description
public
DatagramSocketImpl()

Constructor for subclasses to call.

Method Summary

Modifier and TypeMethod and Description
protected abstract void
bind(int
the local port
lport
,
InetAddress
the local address
laddr
)

Binds a datagram socket to a local port and address.

protected abstract void
close()

Close the socket.

protected void
connect(InetAddress
the remote InetAddress to connect to
address
,
int
the remote port number
port
)

Connects a datagram socket to a remote destination.

protected abstract void
create()

Creates a datagram socket.

pack-priv int
protected void
disconnect()

Disconnects a datagram socket from its remote destination.

protected FileDescriptor

Returns:

a FileDescriptor object representing the datagram socket file descriptor
getFileDescriptor
()

Gets the datagram socket file descriptor.

protected int

Returns:

an int representing the local port value
getLocalPort
()

Gets the local port.

protected <
The type of the socket option value
T
>
T

Returns:

the socket option
getOption
(SocketOption<T>
The socket option
name
)

Called to get a socket option.

protected abstract int

Returns:

an int representing the time-to-live value
getTimeToLive
()

Retrieve the TTL (time-to-live) option.

protected abstract void
join(InetAddress
multicast address to join.
inetaddr
)

Join the multicast group.

protected abstract void
joinGroup(SocketAddress
address to join.
mcastaddr
,
NetworkInterface
specifies the local interface to receive multicast datagram packets
netIf
)

Join the multicast group.

protected abstract void
leave(InetAddress
multicast address to leave.
inetaddr
)

Leave the multicast group.

protected abstract void
leaveGroup(SocketAddress
address to leave.
mcastaddr
,
NetworkInterface
specified the local interface to leave the group at
netIf
)

Leave the multicast group.

protected abstract int

Returns:

the port number which the packet came from.
peek
(InetAddress
an InetAddress object
i
)

Peek at the packet to see who it is from.

protected abstract int

Returns:

the port number which the packet came from.
peekData
(DatagramPacket
the Packet Received.
p
)

Peek at the packet to see who it is from.

protected abstract void
receive(DatagramPacket
the Packet Received.
p
)

Receive the datagram packet.

protected abstract void
send(DatagramPacket
the packet to be sent.
p
)

Sends a datagram packet.

protected <
The type of the socket option value
T
>
void
setOption(SocketOption<T>
The socket option
name
,
T
The value of the socket option. A value of null may be valid for some options.
value
)

Called to set a socket option.

protected abstract void
setTimeToLive(int
an int specifying the time-to-live value
ttl
)

Set the TTL (time-to-live) option.

protected Set<SocketOption<?>>

Returns:

a Set of SocketOptions
supportedOptions
()

Returns a set of SocketOptions supported by this impl and by this impl's socket (DatagramSocket or MulticastSocket)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fdback to summary
protected FileDescriptor fd

The file descriptor object.

localPortback to summary
protected int localPort

The local port number.

Constructor Detail

DatagramSocketImplback to summary
public DatagramSocketImpl()

Constructor for subclasses to call.

Method Detail

bindback to summary
protected abstract void bind(int lport, InetAddress laddr) throws SocketException

Binds a datagram socket to a local port and address.

Parameters
lport:int

the local port

laddr:InetAddress

the local address

Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error.
closeback to summary
protected abstract void close()

Close the socket.

connectback to summary
protected void connect(InetAddress address, int port) throws SocketException

Connects a datagram socket to a remote destination. This associates the remote address with the local socket so that datagrams may only be sent to this destination and received from this destination. This may be overridden to call a native system connect.

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.

Implementation Specification

The default implementation of this method throws SocketException.

Parameters
address:InetAddress

the remote InetAddress to connect to

port:int

the remote port number

Exceptions
SocketException:
may be thrown if the socket cannot be connected to the remote destination
Since
1.4
createback to summary
protected abstract void create() throws SocketException

Creates a datagram socket.

Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error.
dataAvailableback to summary
pack-priv int dataAvailable()
disconnectback to summary
protected void disconnect()

Disconnects a datagram socket from its remote destination.

Implementation Specification

The default implementation of this method throws UncheckedIOException.

Exceptions
UncheckedIOException:
if disconnect fails or no implementation is provided
Since
1.4
getFileDescriptorback to summary
protected FileDescriptor getFileDescriptor()

Gets the datagram socket file descriptor.

Returns:FileDescriptor

a FileDescriptor object representing the datagram socket file descriptor

getLocalPortback to summary
protected int getLocalPort()

Gets the local port.

Returns:int

an int representing the local port value

getOptionback to summary
protected <T> T getOption(SocketOption<T> name) throws IOException

Called to get a socket option.

Implementation Specification

The default implementation of this method first checks that the given socket option name is not null, then throws UnsupportedOperationException. Subclasses should override this method with an appropriate implementation.

Parameters
<T>
The type of the socket option value
name:SocketOption<T>

The socket option

Returns:T

the socket option

Exceptions
IOException:
if an I/O error occurs, or if the socket is closed
UnsupportedOperationException:
if the DatagramSocketImpl does not support the option
NullPointerException:
if name is null
Since
9
getTimeToLiveback to summary
protected abstract int getTimeToLive() throws IOException

Retrieve the TTL (time-to-live) option.

Returns:int

an int representing the time-to-live value

Exceptions
IOException:
if an I/O exception occurs while retrieving the time-to-live option
See Also
setTimeToLive(int)
joinback to summary
protected abstract void join(InetAddress inetaddr) throws IOException

Join the multicast group.

Parameters
inetaddr:InetAddress

multicast address to join.

Exceptions
IOException:
if an I/O exception occurs while joining the multicast group.
joinGroupback to summary
protected abstract void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException

Join the multicast group.

Parameters
mcastaddr:SocketAddress

address to join.

netIf:NetworkInterface

specifies the local interface to receive multicast datagram packets

Exceptions
IOException:
if an I/O exception occurs while joining the multicast group
Since
1.4
leaveback to summary
protected abstract void leave(InetAddress inetaddr) throws IOException

Leave the multicast group.

Parameters
inetaddr:InetAddress

multicast address to leave.

Exceptions
IOException:
if an I/O exception occurs while leaving the multicast group.
leaveGroupback to summary
protected abstract void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException

Leave the multicast group.

Parameters
mcastaddr:SocketAddress

address to leave.

netIf:NetworkInterface

specified the local interface to leave the group at

Exceptions
IOException:
if an I/O exception occurs while leaving the multicast group
Since
1.4
peekback to summary
protected abstract int peek(InetAddress i) throws IOException

Peek at the packet to see who it is from. Updates the specified InetAddress to the address which the packet came from.

Parameters
i:InetAddress

an InetAddress object

Returns:int

the port number which the packet came from.

Exceptions
IOException:
if an I/O exception occurs
PortUnreachableException:
may be thrown if the socket is connected to a currently unreachable destination. Note, there is no guarantee that the exception will be thrown.
peekDataback to summary
protected abstract int peekData(DatagramPacket p) throws IOException

Peek at the packet to see who it is from. The data is copied into the specified DatagramPacket. The data is returned, but not consumed, so that a subsequent peekData/receive operation will see the same data.

Parameters
p:DatagramPacket

the Packet Received.

Returns:int

the port number which the packet came from.

Exceptions
IOException:
if an I/O exception occurs
PortUnreachableException:
may be thrown if the socket is connected to a currently unreachable destination. Note, there is no guarantee that the exception will be thrown.
Since
1.4
receiveback to summary
protected abstract void receive(DatagramPacket p) throws IOException

Receive the datagram packet.

Parameters
p:DatagramPacket

the Packet Received.

Exceptions
IOException:
if an I/O exception occurs while receiving the datagram packet.
PortUnreachableException:
may be thrown if the socket is connected to a currently unreachable destination. Note, there is no guarantee that the exception will be thrown.
sendback to summary
protected abstract void send(DatagramPacket p) throws IOException

Sends a datagram packet. The packet contains the data and the destination address to send the packet to.

Parameters
p:DatagramPacket

the packet to be sent.

Exceptions
IOException:
if an I/O exception occurs while sending the datagram packet.
PortUnreachableException:
may be thrown if the socket is connected to a currently unreachable destination. Note, there is no guarantee that the exception will be thrown.
setOptionback to summary
protected <T> void setOption(SocketOption<T> name, T value) throws IOException

Called to set a socket option.

Implementation Specification

The default implementation of this method first checks that the given socket option name is not null, then throws UnsupportedOperationException. Subclasses should override this method with an appropriate implementation.

Parameters
<T>
The type of the socket option value
name:SocketOption<T>

The socket option

value:T

The value of the socket option. A value of null may be valid for some options.

Exceptions
IOException:
if an I/O error occurs, or if the socket is closed
UnsupportedOperationException:
if the DatagramSocketImpl does not support the option
IllegalArgumentException:
if the value is not valid for the option
NullPointerException:
if name is null
Since
9
setTimeToLiveback to summary
protected abstract void setTimeToLive(int ttl) throws IOException

Set the TTL (time-to-live) option.

Parameters
ttl:int

an int specifying the time-to-live value

Exceptions
IOException:
if an I/O exception occurs while setting the time-to-live option.
See Also
getTimeToLive()
supportedOptionsback to summary
protected Set<SocketOption<?>> supportedOptions()

Returns a set of SocketOptions supported by this impl and by this impl's socket (DatagramSocket or MulticastSocket)

Implementation Specification

The default implementation of this method returns an empty set. Subclasses should override this method with an appropriate implementation.

Returns:Set<SocketOption<?>>

a Set of SocketOptions

Since
9