This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


java.net
class DatagramPacket

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

public final class DatagramPacket
extends Object

This class represents a datagram packet.

Datagram packets are used to implement a connectionless packet delivery service. Each message is routed from one machine to another based solely on information contained within that packet. Multiple packets sent from one machine to another might be routed differently, and might arrive in any order. Packet delivery is not guaranteed.

See Also (auto-generated):

DatagramSocket

InetAddress

Thread


Constructor Summary
DatagramPacket(byte[] buf, int length)

          Constructs a DatagramPacket for receiving packets of length length.
DatagramPacket(byte[] buf, int length, InetAddress address, int port)

          Constructs a datagram packet for sending packets of length length to the specified port number on the specified host.
DatagramPacket(byte[] buf, int offset, int length)

          Constructs a DatagramPacket for receiving packets of length length, specifying an offset into the buffer.
DatagramPacket(byte[] buf, int offset, int length, InetAddress address, int port)

          Constructs a datagram packet for sending packets of length length with offset ioffsetto the specified port number on the specified host.
DatagramPacket(byte[] buf, int offset, int length, SocketAddress address)

          Constructs a datagram packet for sending packets of length length with offset ioffsetto the specified port number on the specified host.
DatagramPacket(byte[] buf, int length, SocketAddress address)

          Constructs a datagram packet for sending packets of length length to the specified port number on the specified host.
 
Method Summary
 InetAddress

          Returns the IP address of the machine to which this datagram is being sent or from which the datagram was received.
 byte[]

          Returns the data buffer.
 int

          Returns the length of the data to be sent or the length of the data received.
 int

          Returns the offset of the data to be sent or the offset of the data received.
 int

          Returns the port number on the remote host to which this datagram is being sent or from which the datagram was received.
 SocketAddress

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

          Sets the IP address of the machine to which this datagram is being sent.
 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
setPort(int iport)

          Sets the port number on the remote host to which this datagram is being sent.
 void

          Sets the SocketAddress (usually IP address + port number) of the remote host to which this datagram is being sent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatagramPacket

public DatagramPacket(byte[] buf,
                      int length)
Constructs a DatagramPacket for receiving packets of length length.

The length argument must be less than or equal to buf.length.

Parameters:
buf - buffer for holding the incoming datagram.
length - the number of bytes to read.

DatagramPacket

public DatagramPacket(byte[] buf,
                      int length,
                      InetAddress address,
                      int port)
Constructs a datagram packet for sending packets of length length to the specified port number on the specified host. The length argument must be less than or equal to buf.length.

Parameters:
buf - the packet data.
length - the packet length.
address - the destination address.
port - the destination port number.

DatagramPacket

public DatagramPacket(byte[] buf,
                      int offset,
                      int length)
Constructs a DatagramPacket for receiving packets of length length, specifying an offset into the buffer.

The length argument must be less than or equal to buf.length.

Parameters:
buf - buffer for holding the incoming datagram.
offset - the offset for the buffer
length - the number of bytes to read.

DatagramPacket

public DatagramPacket(byte[] buf,
                      int offset,
                      int length,
                      InetAddress address,
                      int port)
Constructs a datagram packet for sending packets of length length with offset ioffsetto the specified port number on the specified host. The length argument must be less than or equal to buf.length.

Parameters:
buf - the packet data.
offset - the packet data offset.
length - the packet data length.
address - the destination address.
port - the destination port number.

DatagramPacket

public DatagramPacket(byte[] buf,
                      int offset,
                      int length,
                      SocketAddress address)
               throws SocketException
Constructs a datagram packet for sending packets of length length with offset ioffsetto the specified port number on the specified host. The length argument must be less than or equal to buf.length.

Parameters:
buf - the packet data.
offset - the packet data offset.
length - the packet data length.
address - the destination socket address.
Throws:
SocketException

DatagramPacket

public DatagramPacket(byte[] buf,
                      int length,
                      SocketAddress address)
               throws SocketException
Constructs a datagram packet for sending packets of length length to the specified port number on the specified host. The length argument must be less than or equal to buf.length.

Parameters:
buf - the packet data.
length - the packet length.
address - the destination address.
Throws:
SocketException
Method Detail

getAddress

public synchronized InetAddress getAddress()
Returns the IP address of the machine to which this datagram is being sent or from which the datagram was received.

Returns:
the IP address of the machine to which this datagram is being sent or from which the datagram was received.

getData

public synchronized 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

getLength

public synchronized 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.

getOffset

public synchronized 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.

getPort

public synchronized int getPort()
Returns the port number on the remote host to which this datagram is being sent or from which the datagram was received.

Returns:
the port number on the remote host to which this datagram is being sent or from which the datagram was received.

getSocketAddress

public synchronized 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

setAddress

public synchronized void setAddress(InetAddress iaddr)
Sets the IP address of the machine to which this datagram is being sent.

Parameters:
iaddr - the InetAddress

setData

public synchronized 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.

setData

public synchronized 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

setLength

public synchronized 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.

setPort

public synchronized void setPort(int iport)
Sets the port number on the remote host to which this datagram is being sent.

Parameters:
iport - the port number

setSocketAddress

public synchronized void setSocketAddress(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


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.