Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Class java.net.DatagramPacket

java.lang.Object
    |
    +----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.

Since:
JDK1.0

Constructor Summary
 DatagramPacket(byte[] ibuf, int ilength)
Constructs a DatagramPacket for receiving packets of length ilength.
 DatagramPacket(byte[] ibuf, int ilength, InetAddress iaddr, int iport)
Constructs a datagram packet for sending packets of length ilength to the specified port number on the specified host.
 

Method Summary
InetAddress  getAddress()
Returns the IP address of the machine to which this datagram is being sent or from which the datagram was received.
byte[]  getData()
Returns the data received or the data to be sent.
int  getLength()
Returns the length of the data to be sent or the length of the data received.
int  getPort()
Returns the port number on the remote host to which this datagram is being sent or from which the datagram was received.
void  setAddress(InetAddress iaddr)
 
void  setData(byte[] ibuf)
Set the data buffer for this packet.
void  setLength(int ilength)
Set the length for this packet.
void  setPort(int iport)
 
 
Methods inherited from class java.lang.Object
 clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatagramPacket

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

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

Parameters:
ibuf - buffer for holding the incoming datagram.
ilength - the number of bytes to read.

DatagramPacket

public DatagramPacket(byte[] ibuf,
                      int ilength,
                      InetAddress iaddr,
                      int iport)
Constructs a datagram packet for sending packets of length ilength to the specified port number on the specified host. The length argument must be less than or equal to ibuf.length.
Parameters:
ibuf - the packet data.
ilength - the packet length.
iaddr - the destination address.
iport - the destination port number.
See Also:
InetAddress
Method Detail

getAddress

public 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.
See Also:
InetAddress

getPort

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

getData

public byte[] getData()
Returns the data received or the data to be sent.
Returns:
the data received or the data to be sent.

getLength

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

setAddress

public void setAddress(InetAddress iaddr)

setPort

public void setPort(int iport)

setData

public void setData(byte[] ibuf)
Set the data buffer for this packet. If the length of the packet length is greater than the length of argument to this method, the length is reset to the the length of the argument.
Parameters:
ibuf - the buffer to set for this packet.
Throws:
NullPointerException - if the argument is null.
See Also:
getLength, getData

setLength

public void setLength(int ilength)
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 length of the packet's buffer.
Parameters:
ilength - the length to set for this packet.
Throws:
IllegalArgumentException - if the length is negative of if the length is greater than the packet's data buffer length.
See Also:
getLength, setData

Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.