Build 1.0_r1(from source)

java.net
Class DatagramSocketImpl

java.lang.Object
  extended by java.net.DatagramSocketImpl
All Implemented Interfaces:
SocketOptions

public abstract class DatagramSocketImpl
extends Object
implements SocketOptions

The abstract superclass of datagram & multicast socket implementations.


Field Summary
protected  FileDescriptor fd
           
protected  int localPort
           
 
Fields inherited from interface java.net.SocketOptions
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 Summary
DatagramSocketImpl()
          Constructs an unbound datagram socket implementation.
 
Method Summary
protected abstract  void bind(int port, InetAddress addr)
          Bind the datagram socket to the nominated localhost/port.
protected abstract  void close()
          Close the socket.
protected  void connect(InetAddress inetAddr, int port)
          Connect the 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()
          Disconnect the socket from the remote address and port.
protected  FileDescriptor getFileDescriptor()
          Answer the FileDescriptor, which will be invalid if the socket is closed or not bound.
(package private)  InetAddress getLocalAddress()
          Answer the local address to which the socket is bound.
protected  int getLocalPort()
          Answer the local port.
abstract  Object getOption(int optID)
          Answer the nominated socket option.
protected abstract  int getTimeToLive()
          Answer 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)
          Add this socket to the multicast group.
protected abstract  void joinGroup(SocketAddress addr, NetworkInterface netInterface)
          Add this socket to the multicast group.
protected abstract  void leave(InetAddress addr)
          Remove the socket from the multicast group.
protected abstract  void leaveGroup(SocketAddress addr, NetworkInterface netInterface)
          Remove the socket from the multicast group.
protected abstract  int peek(InetAddress sender)
          Peek at the incoming packet to this socket and answer the sender's address into sender.
protected abstract  int peekData(DatagramPacket pack)
          Receive data into the supplied datagram packet by peeking.
protected abstract  void receive(DatagramPacket pack)
          Receive data into the supplied datagram packet.
protected abstract  void send(DatagramPacket pack)
          Sends the supplied datagram packet.
abstract  void setOption(int optID, Object val)
          Set the nominated socket option.
protected abstract  void setTimeToLive(int ttl)
          Set the time-to-live (TTL) for multicast packets sent on this socket.
protected abstract  void setTTL(byte ttl)
          Deprecated. Replaced by setTimeToLive(int)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fd

protected FileDescriptor fd

localPort

protected int localPort
Constructor Detail

DatagramSocketImpl

public DatagramSocketImpl()
Constructs an unbound datagram socket implementation.

Method Detail

bind

protected abstract void bind(int port,
                             InetAddress addr)
                      throws SocketException
Bind the datagram socket to the nominated localhost/port. Sockets must be bound prior to attempting to send or receive data.

Parameters:
port - the port on the localhost to bind
addr - the address on the multihomed localhost to bind
Throws:
SocketException - if an error occurred during bind, such as if the port was already bound

close

protected abstract void close()
Close the socket.


create

protected abstract void create()
                        throws SocketException
This method allocates the socket descriptor in the underlying operating system.

Throws:
SocketException

getFileDescriptor

protected FileDescriptor getFileDescriptor()
Answer the FileDescriptor, which will be invalid if the socket is closed or not bound.

Returns:
FileDescriptor the socket file descriptor

getLocalAddress

InetAddress getLocalAddress()
Answer the local address to which the socket is bound.

Returns:
InetAddress the local address to which the socket is bound.

getLocalPort

protected int getLocalPort()
Answer the local port. If the socket was bound to any available port, as flagged by a localPort value of -1, query the IP stack.

Returns:
int the local port to which the socket is bound.

getOption

public abstract Object getOption(int optID)
                          throws SocketException
Answer the nominated socket option.

Specified by:
getOption in interface SocketOptions
Parameters:
optID - the socket option to retrieve
Returns:
Object the option value
Throws:
SocketException - thrown if an error occurs while accessing the option

getTTL

@Deprecated
protected abstract byte getTTL()
                        throws IOException
Deprecated. Replaced by getTimeToLive()

Answer the time-to-live (TTL) for multicast packets sent on this socket.

Returns:
java.net.InetAddress
Throws:
IOException - The exception description.
See Also:
getTimeToLive()

getTimeToLive

protected abstract int getTimeToLive()
                              throws IOException
Answer the time-to-live (TTL) for multicast packets sent on this socket.

Returns:
int
Throws:
IOException - The exception description.

join

protected abstract void join(InetAddress addr)
                      throws IOException
Add this socket to the multicast group. A socket must join a group before data may be received. A socket may be a member of multiple groups but may join any group once.

Parameters:
addr - the multicast group to be joined
Throws:
IOException - may be thrown while joining a group

joinGroup

protected abstract void joinGroup(SocketAddress addr,
                                  NetworkInterface netInterface)
                           throws IOException
Add this socket to the multicast group. A socket must join a group before data may be received. A socket may be a member of multiple groups but may join any group once.

Parameters:
addr - the multicast group to be joined
netInterface - the network interface on which the addresses should be dropped
Throws:
IOException - may be thrown while joining a group

leave

protected abstract void leave(InetAddress addr)
                       throws IOException
Remove the socket from the multicast group.

Parameters:
addr - the multicast group to be left
Throws:
IOException - May be thrown while leaving the group

leaveGroup

protected abstract void leaveGroup(SocketAddress addr,
                                   NetworkInterface netInterface)
                            throws IOException
Remove the socket from the multicast group.

Parameters:
addr - the multicast group to be left
netInterface - the network interface on which the addresses should be dropped
Throws:
IOException - May be thrown while leaving the group

peek

protected abstract int peek(InetAddress sender)
                     throws IOException
Peek at the incoming packet to this socket and answer the sender's address into sender. The method will block until a packet is received or timeout expires and returns the sender's port.

Throws:
IOException - if a read error or timeout occurs

receive

protected abstract void receive(DatagramPacket pack)
                         throws IOException
Receive data into the supplied datagram packet. This call will block until either data is received or, if a timeout is set, the timeout expires. If the timeout expires, the InterruptedIOException is thrown.

Throws:
IOException - if a read error or timeout occurs

send

protected abstract void send(DatagramPacket pack)
                      throws IOException
Sends the supplied datagram packet. The packet contains the destination host & port.

Parameters:
pack - DatagramPacket to send
Throws:
IOException - if a write error occurs

setOption

public abstract void setOption(int optID,
                               Object val)
                        throws SocketException
Set the nominated socket option.

Specified by:
setOption in interface SocketOptions
Parameters:
optID - the socket option to set
val - the option value
Throws:
SocketException - thrown if an error occurs while setting the option

setTimeToLive

protected abstract void setTimeToLive(int ttl)
                               throws IOException
Set the time-to-live (TTL) for multicast packets sent on this socket.

Parameters:
ttl - the time-to-live, 0 < ttl <= 255
Throws:
IOException - The exception thrown while setting the TTL

setTTL

@Deprecated
protected abstract void setTTL(byte ttl)
                        throws IOException
Deprecated. Replaced by setTimeToLive(int)

Set the time-to-live (TTL) for multicast packets sent on this socket.

Parameters:
ttl - the time-to-live, 0 < ttl <= 255
Throws:
IOException - The exception thrown while setting the TTL
See Also:
setTimeToLive(int)

connect

protected void connect(InetAddress inetAddr,
                       int port)
                throws SocketException
Connect the socket to the specified remote address and port.

Parameters:
inetAddr - the remote address
port - the remote port
Throws:
SocketException - possibly thrown, if the datagram socket cannot be connected to the specified remote address and port

disconnect

protected void disconnect()
Disconnect the socket from the remote address and port.


peekData

protected abstract int peekData(DatagramPacket pack)
                         throws IOException
Receive data into the supplied datagram packet by peeking. The data is not removed and will be received by another peekData() or receive() call. This call will block until either data is received or, if a timeout is set, the timeout expires.

Parameters:
pack - the DatagramPacket used to store the data
Returns:
the port the packet was received from
Throws:
IOException - if an error occurs

Build 1.0_r1(from source)

Please submit a feedback, bug or feature