public abstract class DatagramSocketImpl extends Object implements SocketOptions
Modifier and Type | Field and Description |
---|---|
protected FileDescriptor |
fd
File descriptor that is used to address this socket.
|
protected int |
localPort
The number of the local port to which this socket is bound.
|
IP_MULTICAST_IF, IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS, SO_BINDADDR, SO_BROADCAST, SO_KEEPALIVE, SO_LINGER, SO_OOBINLINE, SO_RCVBUF, SO_REUSEADDR, SO_SNDBUF, SO_TIMEOUT, TCP_NODELAY
Constructor and Description |
---|
DatagramSocketImpl()
Constructs an unbound datagram socket implementation.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
bind(int port,
InetAddress addr)
Binds the datagram socket to the given localhost/port.
|
protected abstract void |
close()
Closes this socket.
|
protected void |
connect(InetAddress inetAddr,
int port)
Connects this socket to the specified remote address and port.
|
protected abstract void |
create()
This method allocates the socket descriptor in the underlying operating
system.
|
protected void |
disconnect()
Disconnects this socket from the remote host.
|
protected FileDescriptor |
getFileDescriptor()
Gets the
FileDescriptor of this datagram socket, which is invalid
if the socket is closed or not bound. |
protected int |
getLocalPort()
Returns the local port to which this socket is bound.
|
protected abstract int |
getTimeToLive()
Gets the time-to-live (TTL) for multicast packets sent on this socket.
|
protected abstract byte |
getTTL()
Deprecated.
Replaced by
getTimeToLive() |
protected abstract void |
join(InetAddress addr)
Adds this socket to the multicast group
addr . |
protected abstract void |
joinGroup(SocketAddress addr,
NetworkInterface netInterface)
Adds this socket to the multicast group
addr . |
protected abstract void |
leave(InetAddress addr)
Removes this socket from the multicast group
addr . |
protected abstract void |
leaveGroup(SocketAddress addr,
NetworkInterface netInterface)
Removes this socket from the multicast group
addr . |
protected abstract int |
peek(InetAddress sender)
Peeks at the incoming packet to this socket and returns the address of
the
sender . |
protected abstract int |
peekData(DatagramPacket pack)
Receives data into the supplied datagram packet by peeking.
|
protected abstract void |
receive(DatagramPacket pack)
Receives data and stores it in the supplied datagram packet
pack . |
protected abstract void |
send(DatagramPacket pack)
Sends the given datagram packet
pack . |
protected abstract void |
setTimeToLive(int ttl)
Sets the time-to-live (TTL) option for multicast packets sent on this
socket.
|
protected abstract void |
setTTL(byte ttl)
Deprecated.
Replaced by
setTimeToLive(int) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getOption, setOption
protected FileDescriptor fd
protected int localPort
public DatagramSocketImpl()
protected abstract void bind(int port, InetAddress addr) throws SocketException
port
- the port on the localhost to bind.addr
- the address on the multihomed localhost to bind.SocketException
- if an error occurs while binding, for example, if the port
has been already bound.protected abstract void close()
protected abstract void create() throws SocketException
SocketException
- if an error occurs while creating the socket.protected FileDescriptor getFileDescriptor()
FileDescriptor
of this datagram socket, which is invalid
if the socket is closed or not bound.protected int getLocalPort()
@Deprecated protected abstract byte getTTL() throws IOException
getTimeToLive()
IOException
- if an error occurs while getting the time-to-live option
value.getTimeToLive()
protected abstract int getTimeToLive() throws IOException
IOException
- if an error occurs while getting the time-to-live option
value.protected abstract void join(InetAddress addr) throws IOException
addr
. A socket must join
a group before being able to receive data. Further, a socket may be a
member of multiple groups but may join any group only once.addr
- the multicast group to which this socket has to be joined.IOException
- if an error occurs while joining the specified multicast
group.protected abstract void joinGroup(SocketAddress addr, NetworkInterface netInterface) throws IOException
addr
. A socket must join
a group before being able to receive data. Further, a socket may be a
member of multiple groups but may join any group only once.addr
- the multicast group to which this socket has to be joined.netInterface
- the local network interface which will receive the multicast
datagram packets.IOException
- if an error occurs while joining the specified multicast
group.protected abstract void leave(InetAddress addr) throws IOException
addr
.addr
- the multicast group to be left.IOException
- if an error occurs while leaving the group or no multicast
address was assigned.protected abstract void leaveGroup(SocketAddress addr, NetworkInterface netInterface) throws IOException
addr
.addr
- the multicast group to be left.netInterface
- the local network interface on which this socket has to be
removed.IOException
- if an error occurs while leaving the group.protected abstract int peek(InetAddress sender) throws IOException
sender
. The method will block until a packet is received or
timeout expires.sender
- the origin address of a packet.sender
as an integer value.IOException
- if an error or a timeout occurs while reading the address.protected abstract void receive(DatagramPacket pack) throws IOException
pack
.
This call will block until either data has been received or, if a timeout
is set, the timeout has expired. If the timeout expires an InterruptedIOException
is thrown.pack
- the datagram packet container to fill in the received data.IOException
- if an error or timeout occurs while receiving data.protected abstract void send(DatagramPacket pack) throws IOException
pack
. The packet contains the
data and the address and port information of the target host as well.pack
- the datagram packet to be sent.IOException
- if an error occurs while sending the packet.protected abstract void setTimeToLive(int ttl) throws IOException
ttl
- the time-to-live option value. Valid values are 0 < ttl
<= 255.IOException
- if an error occurs while setting the option.@Deprecated protected abstract void setTTL(byte ttl) throws IOException
setTimeToLive(int)
ttl
- the time-to-live option value. Valid values are 0 < ttl
<= 255.IOException
- if an error occurs while setting the option.setTimeToLive(int)
protected void connect(InetAddress inetAddr, int port) throws SocketException
inetAddr
- the address of the target host which has to be connected.port
- the port on the target host which has to be connected.SocketException
- if the datagram socket cannot be connected to the
specified remote address and port.protected void disconnect()
protected abstract int peekData(DatagramPacket pack) throws IOException
peekData()
or receive()
call. This call blocks until
either data has been received or, if a timeout is set, the timeout has
been expired.pack
- the datagram packet used to store the data.IOException
- if an error occurs while peeking at the data.