java.net
Class DatagramPacket
java.lang.Object
|
+--java.net.DatagramPacket
public final class
DatagramPacketextends
Object This class models a packet of data that is to be sent across the network
using a connectionless protocol such as UDP. It contains the data
to be send, as well as the destination address and port. Note that
datagram packets can arrive in any order and are not guaranteed to be
delivered at all.
This class can also be used for receiving data from the network.
Note that for all method below where the buffer length passed by the
caller cannot exceed the actually length of the byte array passed as
the buffer, if this condition is not true, then the method silently
reduces the length value to maximum allowable value.
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.
Authors:- Warren Levy <warrenl@cygnus.com>
- Aarom M. Renn (arenn@urbanophile.com) (Documentation comments)
DatagramPacket(byte[] buf, int offset, int length)
|
DatagramPacket(byte[] buf, int length)
|
DatagramPacket(byte[] buf, int offset, int length, java.net.InetAddress address, int port)
|
DatagramPacket(byte[] buf, int length, java.net.InetAddress address, int port)
|
DatagramPacket(byte[] buf, int offset, int length, java.net.SocketAddress address)
|
DatagramPacket(byte[] buf, int length, java.net.SocketAddress address)
|
DatagramPacket
public DatagramPacket(byte[] buf, int length)
Initializes a new instance of DatagramPacket
for
receiving packets from the network.
Parameters:
DatagramPacket
public DatagramPacket(byte[] buf, int offset, int length)
This method initializes a new instance of DatagramPacket
which has the specified buffer, offset, and length.
Since:Parameters:
DatagramPacket
public DatagramPacket(byte[] buf, int offset, int length, java.net.InetAddress address, int port)
Initializes a new instance of DatagramPacket
for
transmitting packets across the network.
Since:Parameters:
DatagramPacket
public DatagramPacket(byte[] buf, int offset, int length, java.net.SocketAddress address)
Initializes a new instance of DatagramPacket
for
transmitting packets across the network.
Since:Parameters:
Throws:
DatagramPacket
public DatagramPacket(byte[] buf, int length, java.net.InetAddress address, int port)
Initializes a new instance of DatagramPacket
for
transmitting packets across the network.
Parameters:
DatagramPacket
public DatagramPacket(byte[] buf, int length, java.net.SocketAddress address)
Initializes a new instance of DatagramPacket
for
transmitting packets across the network.
Since:Parameters:
Throws:
getAddress
public synchronized InetAddress getAddress()
Returns the address that this packet is being sent to or, if it was used
to receive a packet, the address that is was received from. If the
constructor that doesn not take an address was used to create this object
and no packet was actually read into this object, then this method
returns null
.
Returns:
- The address for this packet.
getData
public synchronized byte[] getData()
Returns the data buffer for this packet
Returns:
- This packet's data buffer
getLength
public synchronized int getLength()
Returns the length of the data in the buffer
Returns:
getOffset
public synchronized int getOffset()
This method returns the current offset value into the data buffer
where data will be sent from.
Since:Returns:
getPort
public synchronized int getPort()
Returns the port number this packet is being sent to or, if it was used
to receive a packet, the port that it was received from. If the
constructor that doesn not take an address was used to create this object
and no packet was actually read into this object, then this method
will return 0.
Returns:
- The port number for this packet
getSocketAddress
public SocketAddress getSocketAddress()
Gets the socket address of the host this packet
will be sent to/is coming from
Since:Returns:
- The socket address of the remote host
setAddress
public synchronized void setAddress(java.net.InetAddress iaddr)
This sets the address to which the data packet will be transmitted.
Since:Parameters:
setData
public synchronized void setData(byte[] buf)
Sets the data buffer for this packet.
Since:Parameters:
Throws:
setData
public synchronized void setData(byte[] buf, int offset, int length)
This method sets the data buffer for the packet.
Since:Parameters:
Throws:
setLength
public synchronized void setLength(int length)
Sets the length of the data in the buffer.
Since:Parameters:
Throws:
setPort
public synchronized void setPort(int iport)
This sets the port to which the data packet will be transmitted.
Since:Parameters:
setSocketAddress
public void setSocketAddress(java.net.SocketAddress address)
Sets the address of the remote host this package will be sent
Since:Parameters:
Throws:
This class can also be used for receiving data from the network.
Note that for all method below where the buffer length passed by the caller cannot exceed the actually length of the byte array passed as the buffer, if this condition is not true, then the method silently reduces the length value to maximum allowable value. 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.