java.net
public
final
class
java.net.DatagramPacket
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.
Summary
Public Constructors
|
|
|
|
|
|
DatagramPacket(byte[] data, int length) |
|
|
|
|
|
|
DatagramPacket(byte[] data, int offset, int length) |
|
|
|
|
|
|
DatagramPacket(byte[] data, int offset, int length, InetAddress host, int aPort) |
|
|
|
|
|
|
DatagramPacket(byte[] data, int length, InetAddress host, int port) |
|
|
|
|
|
|
DatagramPacket(byte[] data, int length, SocketAddress sockAddr) |
|
|
|
|
|
|
DatagramPacket(byte[] data, int offset, int length, SocketAddress sockAddr) |
Public Methods
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Public Constructors
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
|
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
|
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
|
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
|
public
DatagramPacket(byte[] data, int length, SocketAddress sockAddr)
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
|
public
DatagramPacket(byte[] data, int offset, int length, SocketAddress sockAddr)
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
|
Public Methods
public
synchronized
InetAddress
getAddress()
Answer the IP address of the machine that is the target or sender of this
datagram.
Returns
- InetAddress the target host address
public
synchronized
byte[]
getData()
Answer the data sent or received in this datagram.
Returns
- byte[] the data sent/received
public
synchronized
int
getLength()
Answer the length of the data sent or received in this datagram.
Returns
- int the length of the sent/received data
public
synchronized
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
public
synchronized
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
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.
Parameters
addr
| the target host address
|
public
synchronized
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
|
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.
Parameters
len
| the length of the data to be sent
|
public
synchronized
void
setPort(int aPort)
Set the port number of the target machine of this datagram.
Parameters
aPort
| the target host port
|
public
synchronized
void
setSocketAddress(SocketAddress sockAddr)
Set the SocketAddress for this packet.
Parameters
sockAddr
| the machine address and port
|