| java.lang.Object java.net.DatagramPacket
DatagramPacket | final public class DatagramPacket (Code) | | 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 | |
InetAddress | address | int | capacity Size of internal buffer that is used to store received data. | byte[] | data | int | length Length of the data to be sent or size of data that was received via
DatagramSocket#receive() method call. | int | offset | int | port |
Constructor Summary | |
public | DatagramPacket(byte[] data, int length) Constructs a new DatagramPacket suitable for receiving
datagram packets of length up to length . | 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 . | 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. | public | DatagramPacket(byte[] data, int length, InetAddress host, int port) Constructs a new DatagramPacket suitable for sending
packets to the nominated host/port. | public | DatagramPacket(byte[] data, int length, SocketAddress sockAddr) Constructs a new DatagramPacket suitable for sending
packets to the nominated host/port. | public | DatagramPacket(byte[] data, int offset, int length, SocketAddress sockAddr) Constructs a new DatagramPacket suitable for sending
packets to the nominated host/port. |
Method Summary | |
public synchronized InetAddress | getAddress() Answer the IP address of the machine that is the target or sender of this
datagram. | public synchronized byte[] | getData() Answer the data sent or received in this datagram. | public synchronized int | getLength() Answer the length of the data sent or received in this datagram. | public synchronized int | getOffset() Answer the offset of the data sent or received in this datagram buffer. | public synchronized int | getPort() Answer the port number of the target or sender machine of this datagram. | public synchronized SocketAddress | getSocketAddress() Answer the SocketAddress for this packet. | public synchronized void | setAddress(InetAddress addr) Set the IP address of the machine that is the target of this datagram. | public synchronized void | setData(byte[] buf, int anOffset, int aLength) Set the data buffer for this datagram. | public synchronized void | setData(byte[] buf) Set the data sent in this datagram. | public synchronized void | setLength(int len) Set the length of the data sent in this datagram. | public synchronized void | setPort(int aPort) Set the port number of the target machine of this datagram. | public synchronized void | setSocketAddress(SocketAddress sockAddr) Set the SocketAddress for this packet. |
capacity | int capacity(Code) | | Size of internal buffer that is used to store received data. Should be
greater or equal to "length" field.
|
length | int length(Code) | | Length of the data to be sent or size of data that was received via
DatagramSocket#receive() method call.
|
DatagramPacket | public DatagramPacket(byte[] data, int length)(Code) | | Constructs a new DatagramPacket suitable for receiving
datagram packets of length up to length .
Parameters: data - byte array to store the read characters Parameters: length - length of the data buffer |
DatagramPacket | public DatagramPacket(byte[] data, int offset, int length)(Code) | | 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 Parameters: offset - the offset into the byte array Parameters: length - length of the data buffer |
DatagramPacket | public DatagramPacket(byte[] data, int offset, int length, InetAddress host, int aPort)(Code) | | 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 Parameters: offset - the offset in to read/write from Parameters: length - length of the data buffer Parameters: host - address of the target host Parameters: aPort - target host port |
DatagramPacket | public DatagramPacket(byte[] data, int length, InetAddress host, int port)(Code) | | 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 Parameters: length - length of the data buffer Parameters: host - address of the target host Parameters: port - target host port |
DatagramPacket | public DatagramPacket(byte[] data, int length, SocketAddress sockAddr) throws SocketException(Code) | | 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 Parameters: length - length of the data buffer Parameters: sockAddr - the machine address and port |
DatagramPacket | public DatagramPacket(byte[] data, int offset, int length, SocketAddress sockAddr) throws SocketException(Code) | | 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 Parameters: offset - the offset in to read/write from Parameters: length - length of the data buffer Parameters: sockAddr - the machine address and port |
getAddress | public synchronized InetAddress getAddress()(Code) | | Answer the IP address of the machine that is the target or sender of this
datagram.
InetAddress the target host address |
getData | public synchronized byte[] getData()(Code) | | Answer the data sent or received in this datagram.
byte[] the data sent/received |
getLength | public synchronized int getLength()(Code) | | Answer the length of the data sent or received in this datagram.
int the length of the sent/received data |
getOffset | public synchronized int getOffset()(Code) | | Answer the offset of the data sent or received in this datagram buffer.
int the offset of the start of the sent/received data |
getPort | public synchronized int getPort()(Code) | | Answer the port number of the target or sender machine of this datagram.
int for received packets, the sender address and for sentpackets, the target host |
getSocketAddress | public synchronized SocketAddress getSocketAddress()(Code) | | Answer the SocketAddress for this packet.
|
setAddress | public synchronized void setAddress(InetAddress addr)(Code) | | Set the IP address of the machine that is the target of this datagram.
Parameters: addr - the target host address |
setData | public synchronized void setData(byte[] buf, int anOffset, int aLength)(Code) | | Set the data buffer for this datagram.
Parameters: buf - the data to be sent Parameters: anOffset - the offset into the data Parameters: aLength - the length of the data to be sent |
setData | public synchronized void setData(byte[] buf)(Code) | | Set the data sent in this datagram.
Parameters: buf - the data to be sent |
setLength | public synchronized void setLength(int len)(Code) | | Set the length of the data sent in this datagram.
Parameters: len - the length of the data to be sent |
setPort | public synchronized void setPort(int aPort)(Code) | | Set the port number of the target machine of this datagram.
Parameters: aPort - the target host port |
setSocketAddress | public synchronized void setSocketAddress(SocketAddress sockAddr)(Code) | | Set the SocketAddress for this packet.
Parameters: sockAddr - the machine address and port |
|
|