Build 1.0_r1(from source)

java.net
Class DatagramPacket

java.lang.Object
  extended by java.net.DatagramPacket

public final class DatagramPacket
extends Object

This class models a datagram packet to be sent or received. The DatagramPacket(byte[], int, InetAddress, int) constructor is used for packets to be sent, while the DatagramPacket(byte[], int) constructor is used for received packets.

See Also:
DatagramSocket

Field Summary
(package private)  InetAddress address
           
(package private)  byte[] data
           
(package private)  int length
           
(package private)  int offset
           
(package private)  int port
           
 
Constructor Summary
DatagramPacket(byte[] data, int length)
          Constructs a new DatagramPacket suitable for receiving datagram packets of length up to length.
DatagramPacket(byte[] data, int length, InetAddress host, int port)
          Constructs a new DatagramPacket suitable for sending packets to the nominated host/port.
DatagramPacket(byte[] data, int offset, int length)
          Constructs a new DatagramPacket suitable for receiving datagram packets of length up to length, with an offset into the buffer offset.
DatagramPacket(byte[] data, int offset, int length, InetAddress host, int aPort)
          Constructs a new DatagramPacket suitable for sending packets to the nominated host/port.
DatagramPacket(byte[] data, int offset, int length, SocketAddress sockAddr)
          Constructs a new DatagramPacket suitable for sending packets to the nominated host/port.
DatagramPacket(byte[] data, int length, SocketAddress sockAddr)
          Constructs a new DatagramPacket suitable for sending packets to the nominated host/port.
 
Method Summary
 InetAddress getAddress()
          Answer the IP address of the machine that is the target or sender of this datagram.
 byte[] getData()
          Answer the data sent or received in this datagram.
 int getLength()
          Answer the length of the data sent or received in this datagram.
 int getOffset()
          Answer the offset of the data sent or received in this datagram buffer.
 int getPort()
          Answer the port number of the target or sender machine of this datagram.
 SocketAddress getSocketAddress()
          Answer the SocketAddress for this packet.
 void setAddress(InetAddress addr)
          Set the IP address of the machine that is the target of this datagram.
 void setData(byte[] buf)
          Set the data sent in this datagram.
 void setData(byte[] buf, int anOffset, int aLength)
          Set the data buffer for this datagram.
 void setLength(int len)
          Set the length of the data sent in this datagram.
 void setPort(int aPort)
          Set the port number of the target machine of this datagram.
 void setSocketAddress(SocketAddress sockAddr)
          Set the SocketAddress for this packet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

byte[] data

length

int length

address

InetAddress address

port

int port

offset

int offset
Constructor Detail

DatagramPacket

public DatagramPacket(byte[] data,
                      int length)
Constructs a new DatagramPacket suitable for receiving datagram packets of length up to length.

Parameters:
data - byte array to store the read characters
length - length of the data buffer

DatagramPacket

public DatagramPacket(byte[] data,
                      int offset,
                      int length)
Constructs a new DatagramPacket suitable for receiving datagram packets of length up to length, with an offset into the buffer offset.

Parameters:
data - byte array to store the read characters
offset - the offset into the byte array
length - length of the data buffer

DatagramPacket

public DatagramPacket(byte[] data,
                      int offset,
                      int length,
                      InetAddress host,
                      int aPort)
Constructs a new DatagramPacket suitable for sending packets to the nominated host/port. The length must be less than or equal to the size of data.

Parameters:
data - byte array to store the read characters
offset - the offset in to read/write from
length - length of the data buffer
host - address of the target host
aPort - target host port

DatagramPacket

public DatagramPacket(byte[] data,
                      int length,
                      InetAddress host,
                      int port)
Constructs a new DatagramPacket suitable for sending packets to the nominated host/port. The length must be less than or equal to the size of data.

Parameters:
data - byte array to store the read characters
length - length of the data buffer
host - address of the target host
port - target host port

DatagramPacket

public DatagramPacket(byte[] data,
                      int length,
                      SocketAddress sockAddr)
               throws SocketException
Constructs a new DatagramPacket suitable for sending packets to the nominated host/port. The length must be less than or equal to the size of data.

Parameters:
data - byte array to store the read characters
length - length of the data buffer
sockAddr - the machine address and port
Throws:
SocketException

DatagramPacket

public DatagramPacket(byte[] data,
                      int offset,
                      int length,
                      SocketAddress sockAddr)
               throws SocketException
Constructs a new DatagramPacket suitable for sending packets to the nominated host/port. The length must be less than or equal to the size of data.

Parameters:
data - byte array to store the read characters
offset - the offset in to read/write from
length - length of the data buffer
sockAddr - the machine address and port
Throws:
SocketException
Method Detail

getAddress

public InetAddress getAddress()
Answer the IP address of the machine that is the target or sender of this datagram.

Returns:
InetAddress the target host address

getData

public byte[] getData()
Answer the data sent or received in this datagram.

Returns:
byte[] the data sent/received

getLength

public int getLength()
Answer the length of the data sent or received in this datagram.

Returns:
int the length of the sent/received data

getOffset

public int getOffset()
Answer the offset of the data sent or received in this datagram buffer.

Returns:
int the offset of the start of the sent/received data

getPort

public int getPort()
Answer the port number of the target or sender machine of this datagram.

Returns:
int for received packets, the sender address and for sent packets, the target host

setAddress

public void setAddress(InetAddress addr)
Set the IP address of the machine that is the target of this datagram.

Parameters:
addr - the target host address

setData

public void setData(byte[] buf,
                    int anOffset,
                    int aLength)
Set the data buffer for this datagram.

Parameters:
buf - the data to be sent
anOffset - the offset into the data
aLength - the length of the data to be sent

setData

public void setData(byte[] buf)
Set the data sent in this datagram.

Parameters:
buf - the data to be sent

setLength

public void setLength(int len)
Set the length of the data sent in this datagram.

Parameters:
len - the length of the data to be sent

setPort

public void setPort(int aPort)
Set the port number of the target machine of this datagram.

Parameters:
aPort - the target host port

getSocketAddress

public SocketAddress getSocketAddress()
Answer the SocketAddress for this packet.


setSocketAddress

public void setSocketAddress(SocketAddress sockAddr)
Set the SocketAddress for this packet.

Parameters:
sockAddr - the machine address and port

Build 1.0_r1(from source)

Please submit a feedback, bug or feature