p2ps.imp.net
Interface DatagramPacket

All Known Implementing Classes:
InetDatagramPacket

public interface DatagramPacket

A datagram packet interface. Needed because of the stupid way java.net assumes SocketAddress instances are going to be InetSocketAddresses!

Version:
$Revision: 295 $
Author:
Ian Wang

Method Summary
 byte[] getData()
          Returns the data buffer.
 int getLength()
          Returns the length of the data to be sent or the length of the data received.
 int getOffset()
          Returns the offset of the data to be sent or the offset of the data received.
 java.net.SocketAddress getSocketAddress()
          Gets the SocketAddress (usually IP address + port number) of the remote host that this packet is being sent to or is coming from.
 void setData(byte[] buf)
          Set the data buffer for this packet.
 void setData(byte[] buf, int offset, int length)
          Set the data buffer for this packet.
 void setLength(int length)
          Set the length for this packet.
 void setSocketAddress(java.net.SocketAddress address)
          Sets the SocketAddress (usually IP address + port number) of the remote host to which this datagram is being sent.
 

Method Detail

getData

public byte[] getData()
Returns the data buffer. The data received or the data to be sent starts from the offset in the buffer, and runs for length long.

Returns:
the buffer used to receive or send data
See Also:
setData(byte[], int, int)

getOffset

public int getOffset()
Returns the offset of the data to be sent or the offset of the data received.

Returns:
the offset of the data to be sent or the offset of the data received.
Since:
JDK1.2

getLength

public int getLength()
Returns the length of the data to be sent or the length of the data received.

Returns:
the length of the data to be sent or the length of the data received.
See Also:
setLength(int)

setData

public void setData(byte[] buf)
Set the data buffer for this packet. With the offset of this DatagramPacket set to 0, and the length set to the length of buf.

Parameters:
buf - the buffer to set for this packet.
Throws:
java.lang.NullPointerException - if the argument is null.
Since:
JDK1.1
See Also:
getLength(), getData()

setData

public void setData(byte[] buf,
                    int offset,
                    int length)
Set the data buffer for this packet. This sets the data, length and offset of the packet.

Parameters:
buf - the buffer to set for this packet
offset - the offset into the data
length - the length of the data and/or the length of the buffer used to receive data
Throws:
java.lang.NullPointerException - if the argument is null
Since:
JDK1.2
See Also:
getData(), getOffset(), getLength()

setLength

public void setLength(int length)
Set the length for this packet. The length of the packet is the number of bytes from the packet's data buffer that will be sent, or the number of bytes of the packet's data buffer that will be used for receiving data. The length must be lesser or equal to the offset plus the length of the packet's buffer.

Parameters:
length - the length to set for this packet.
Throws:
java.lang.IllegalArgumentException - if the length is negative of if the length is greater than the packet's data buffer length.
Since:
JDK1.1
See Also:
getLength(), setData(byte[])

getSocketAddress

public java.net.SocketAddress getSocketAddress()
Gets the SocketAddress (usually IP address + port number) of the remote host that this packet is being sent to or is coming from.

Returns:
the SocketAddress
Since:
1.4
See Also:
setSocketAddress(java.net.SocketAddress)

setSocketAddress

public void setSocketAddress(java.net.SocketAddress address)
Sets the SocketAddress (usually IP address + port number) of the remote host to which this datagram is being sent.

Parameters:
address - the SocketAddress
Throws:
java.lang.IllegalArgumentException - if address is null or is a SocketAddress subclass not supported by this socket
Since:
1.4
See Also:
getSocketAddress()