DatagramSocketImpl
public
abstract
class
DatagramSocketImpl
extends Object
implements
SocketOptions
java.lang.Object | |
↳ | java.net.DatagramSocketImpl |
Abstract datagram and multicast socket implementation base class.
Summary
Inherited constants |
---|
Fields | |
---|---|
protected
FileDescriptor |
fd
The file descriptor object. |
protected
int |
localPort
The local port number. |
Public constructors | |
---|---|
DatagramSocketImpl()
|
Protected methods | |
---|---|
abstract
void
|
bind(int lport, InetAddress laddr)
Binds a datagram socket to a local port and address. |
abstract
void
|
close()
Close the socket. |
void
|
connect(InetAddress address, int port)
Connects a datagram socket to a remote destination. |
abstract
void
|
create()
Creates a datagram socket. |
void
|
disconnect()
Disconnects a datagram socket from its remote destination. |
FileDescriptor
|
getFileDescriptor()
Gets the datagram socket file descriptor. |
int
|
getLocalPort()
Gets the local port. |
<T>
T
|
getOption(SocketOption<T> name)
Called to get a socket option. |
abstract
byte
|
getTTL()
This method was deprecated in API level 15. use getTimeToLive instead. |
abstract
int
|
getTimeToLive()
Retrieve the TTL (time-to-live) option. |
abstract
void
|
join(InetAddress inetaddr)
Join the multicast group. |
abstract
void
|
joinGroup(SocketAddress mcastaddr, NetworkInterface netIf)
Join the multicast group. |
abstract
void
|
leave(InetAddress inetaddr)
Leave the multicast group. |
abstract
void
|
leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf)
Leave the multicast group. |
abstract
int
|
peek(InetAddress i)
Peek at the packet to see who it is from. |
abstract
int
|
peekData(DatagramPacket p)
Peek at the packet to see who it is from. |
abstract
void
|
receive(DatagramPacket p)
Receive the datagram packet. |
abstract
void
|
send(DatagramPacket p)
Sends a datagram packet. |
<T>
void
|
setOption(SocketOption<T> name, T value)
Called to set a socket option. |
abstract
void
|
setTTL(byte ttl)
This method was deprecated in API level 15. use setTimeToLive instead. |
abstract
void
|
setTimeToLive(int ttl)
Set the TTL (time-to-live) option. |
Set<SocketOption<?>>
|
supportedOptions()
Returns a set of SocketOptions supported by this impl and by this impl's socket (DatagramSocket or MulticastSocket) |
Inherited methods | |
---|---|
Fields
Public constructors
Protected methods
bind
protected abstract void bind (int lport, InetAddress laddr)
Binds a datagram socket to a local port and address.
Parameters | |
---|---|
lport |
int : the local port |
laddr |
InetAddress : the local address |
Throws | |
---|---|
SocketException |
if there is an error in the underlying protocol, such as a TCP error. |
connect
protected void connect (InetAddress address, int port)
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.
Parameters | |
---|---|
address |
InetAddress : the remote InetAddress to connect to |
port |
int : the remote port number |
Throws | |
---|---|
SocketException |
may be thrown if the socket cannot be connected to the remote destination |
create
protected abstract void create ()
Creates a datagram socket.
Throws | |
---|---|
SocketException |
if there is an error in the underlying protocol, such as a TCP error. |
disconnect
protected void disconnect ()
Disconnects a datagram socket from its remote destination.
getFileDescriptor
protected FileDescriptor getFileDescriptor ()
Gets the datagram socket file descriptor.
Returns | |
---|---|
FileDescriptor |
a FileDescriptor object representing the datagram socket
file descriptor |
getLocalPort
protected int getLocalPort ()
Gets the local port.
Returns | |
---|---|
int |
an int representing the local port value |
getOption
protected T getOption (SocketOption<T> name)
Called to get a socket option.
Parameters | |
---|---|
name |
SocketOption : The socket option |
Returns | |
---|---|
T |
the socket option |
Throws | |
---|---|
UnsupportedOperationException |
if the DatagramSocketImpl does not support the option |
NullPointerException |
if name is null |
IOException |
if an I/O problem occurs while attempting to set the option |
getTTL
protected abstract byte getTTL ()
This method was deprecated
in API level 15.
use getTimeToLive instead.
Retrieve the TTL (time-to-live) option.
Returns | |
---|---|
byte |
a byte representing the TTL value |
Throws | |
---|---|
IOException |
if an I/O exception occurs while retrieving the time-to-live option |
See also:
getTimeToLive
protected abstract int getTimeToLive ()
Retrieve the TTL (time-to-live) option.
Returns | |
---|---|
int |
an int representing the time-to-live value |
Throws | |
---|---|
IOException |
if an I/O exception occurs while retrieving the time-to-live option |
See also:
join
protected abstract void join (InetAddress inetaddr)
Join the multicast group.
Parameters | |
---|---|
inetaddr |
InetAddress : multicast address to join. |
Throws | |
---|---|
IOException |
if an I/O exception occurs while joining the multicast group. |
joinGroup
protected abstract void joinGroup (SocketAddress mcastaddr, NetworkInterface netIf)
Join the multicast group.
Parameters | |
---|---|
mcastaddr |
SocketAddress : address to join. |
netIf |
NetworkInterface : specifies the local interface to receive multicast
datagram packets |
Throws | |
---|---|
IOException |
if an I/O exception occurs while joining the multicast group |
leave
protected abstract void leave (InetAddress inetaddr)
Leave the multicast group.
Parameters | |
---|---|
inetaddr |
InetAddress : multicast address to leave. |
Throws | |
---|---|
IOException |
if an I/O exception occurs while leaving the multicast group. |
leaveGroup
protected abstract void leaveGroup (SocketAddress mcastaddr, NetworkInterface netIf)
Leave the multicast group.
Parameters | |
---|---|
mcastaddr |
SocketAddress : address to leave. |
netIf |
NetworkInterface : specified the local interface to leave the group at |
Throws | |
---|---|
IOException |
if an I/O exception occurs while leaving the multicast group |
peek
protected abstract int peek (InetAddress i)
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. |
Throws | |
---|---|
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. |
peekData
protected abstract int peekData (DatagramPacket p)
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. |
Throws | |
---|---|
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. |
receive
protected abstract void receive (DatagramPacket p)
Receive the datagram packet.
Parameters | |
---|---|
p |
DatagramPacket : the Packet Received. |
Throws | |
---|---|
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. |
send
protected abstract void send (DatagramPacket p)
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. |
Throws | |
---|---|
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. |
setOption
protected void setOption (SocketOption<T> name, T value)
Called to set a socket option.
Parameters | |
---|---|
name |
SocketOption : The socket option |
value |
T : The value of the socket option. A value of null
may be valid for some options. |
Throws | |
---|---|
UnsupportedOperationException |
if the DatagramSocketImpl does not support the option |
NullPointerException |
if name is null |
IOException |
if an I/O problem occurs while attempting to set the option |
setTTL
protected abstract void setTTL (byte ttl)
This method was deprecated
in API level 15.
use setTimeToLive instead.
Set the TTL (time-to-live) option.
Parameters | |
---|---|
ttl |
byte : a byte specifying the TTL value |
Throws | |
---|---|
IOException |
if an I/O exception occurs while setting the time-to-live option. |
See also:
setTimeToLive
protected abstract void setTimeToLive (int ttl)
Set the TTL (time-to-live) option.
Parameters | |
---|---|
ttl |
int : an int specifying the time-to-live value |
Throws | |
---|---|
IOException |
if an I/O exception occurs while setting the time-to-live option. |
See also:
supportedOptions
protected Set<SocketOption<?>> supportedOptions ()
Returns a set of SocketOptions supported by this impl and by this impl's socket (DatagramSocket or MulticastSocket)
Returns | |
---|---|
Set<SocketOption<?>> |
a Set of SocketOptions |