java.net

Class DatagramSocketImpl

public abstract class DatagramSocketImpl extends Object implements SocketOptions

This abstract class models a datagram socket implementation. An actual implementation class would implement these methods, probably via redirecting them to native code.

Written using on-line Java Platform 1.2 API Specification, as well as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).

Status: Believed complete and correct.

Since: 1.1

Field Summary
protected FileDescriptorfd
The FileDescriptor object for this object.
protected intlocalPort
The local port to which this socket is bound
Constructor Summary
DatagramSocketImpl()
Default, no-argument constructor for subclasses to call.
Method Summary
protected abstract voidbind(int lport, InetAddress laddr)
This method binds the socket to the specified local port and address.
protected abstract voidclose()
This methods closes the socket
protected voidconnect(InetAddress address, int port)
Connects the socket to a host specified by address and port.
protected abstract voidcreate()
Creates a new datagram socket.
protected voiddisconnect()
Disconnects the socket.
protected FileDescriptorgetFileDescriptor()
Returns the FileDescriptor for this socket
protected intgetLocalPort()
Returns the local port this socket is bound to
protected abstract intgetTimeToLive()
This method returns the current Time to Live (TTL) setting on this socket.
protected abstract bytegetTTL()
This method returns the current Time to Live (TTL) setting on this socket.
protected abstract voidjoin(InetAddress inetaddr)
Causes this socket to join the specified multicast group
protected abstract voidjoinGroup(SocketAddress mcastaddr, NetworkInterface netIf)
Causes this socket to join the specified multicast group on a specified device
protected abstract voidleave(InetAddress inetaddr)
Causes the socket to leave the specified multicast group.
protected abstract voidleaveGroup(SocketAddress mcastaddr, NetworkInterface netIf)
Leaves a multicast group
protected abstract intpeek(InetAddress i)
Takes a peek at the next packet received in order to retrieve the address of the sender
protected abstract intpeekData(DatagramPacket p)
Takes a peek at the next packet received.
protected abstract voidreceive(DatagramPacket p)
Receives a packet of data from the network Will block until a packet arrives.
protected abstract voidsend(DatagramPacket p)
Transmits the specified packet of data to the network.
protected abstract voidsetTimeToLive(int ttl)
Sets the Time to Live (TTL) setting on this socket to the specified value.
protected abstract voidsetTTL(byte ttl)
Sets the Time to Live (TTL) setting on this socket to the specified value.

Field Detail

fd

protected FileDescriptor fd
The FileDescriptor object for this object.

localPort

protected int localPort
The local port to which this socket is bound

Constructor Detail

DatagramSocketImpl

public DatagramSocketImpl()
Default, no-argument constructor for subclasses to call.

Method Detail

bind

protected abstract void bind(int lport, InetAddress laddr)
This method binds the socket to the specified local port and address.

Parameters: lport The port number to bind to laddr The address to bind to

Throws: SocketException If an error occurs

close

protected abstract void close()
This methods closes the socket

connect

protected void connect(InetAddress address, int port)
Connects the socket to a host specified by address and port.

Parameters: address The InetAddress of the host to connect to port The port number of the host to connect to

Throws: SocketException If an error occurs

Since: 1.4

create

protected abstract void create()
Creates a new datagram socket.

Throws: SocketException If an error occurs

disconnect

protected void disconnect()
Disconnects the socket.

Since: 1.4

getFileDescriptor

protected FileDescriptor getFileDescriptor()
Returns the FileDescriptor for this socket

Returns: the file descriptor associated with this socket

getLocalPort

protected int getLocalPort()
Returns the local port this socket is bound to

Returns: the local port

getTimeToLive

protected abstract int getTimeToLive()
This method returns the current Time to Live (TTL) setting on this socket.

Returns: the current time-to-live

Throws: IOException If an error occurs

getTTL

protected abstract byte getTTL()

Deprecated: // FIXME: when ?

This method returns the current Time to Live (TTL) setting on this socket. Use getTimeToLive() instead.

Returns: the current time-to-live

Throws: IOException If an error occurs

join

protected abstract void join(InetAddress inetaddr)
Causes this socket to join the specified multicast group

Parameters: inetaddr The multicast address to join with

Throws: IOException If an error occurs

joinGroup

protected abstract void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf)
Causes this socket to join the specified multicast group on a specified device

Parameters: mcastaddr The address to leave netIf The specified network interface to join the group at

Throws: IOException If an error occurs

Since: 1.4

leave

protected abstract void leave(InetAddress inetaddr)
Causes the socket to leave the specified multicast group.

Parameters: inetaddr The multicast address to leave

Throws: IOException If an error occurs

leaveGroup

protected abstract void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf)
Leaves a multicast group

Parameters: mcastaddr The address to join netIf The specified network interface to leave the group at

Throws: IOException If an error occurs

Since: 1.4

peek

protected abstract int peek(InetAddress i)
Takes a peek at the next packet received in order to retrieve the address of the sender

Parameters: i The InetAddress to fill in with the information about the sender if the next packet

Returns: The port number of the sender of the packet

Throws: IOException If an error 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)
Takes a peek at the next packet received. This packet is not consumed. With the next peekData/receive operation this packet will be read again.

Parameters: p The DatagramPacket to fill in with the data sent.

Returns: The port number of the sender of the packet.

Throws: IOException If an error 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

receive

protected abstract void receive(DatagramPacket p)
Receives a packet of data from the network Will block until a packet arrives. The packet info in populated into the passed in DatagramPacket object.

Parameters: p A place to store the incoming packet.

Throws: IOException If an error 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.

send

protected abstract void send(DatagramPacket p)
Transmits the specified packet of data to the network. The destination host and port should be encoded in the packet.

Parameters: p The packet to send

Throws: IOException If an error 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.

setTimeToLive

protected abstract void setTimeToLive(int ttl)
Sets the Time to Live (TTL) setting on this socket to the specified value.

Parameters: ttl The new Time to Live value

Throws: IOException If an error occurs

setTTL

protected abstract void setTTL(byte ttl)

Deprecated:

Sets the Time to Live (TTL) setting on this socket to the specified value. Use setTimeToLive(int) instead.

Parameters: ttl The new Time to Live value

Throws: IOException If an error occurs