All Packages  Class Hierarchy  This Package  Previous  Next  Index

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.


Constructor Index

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

Method Index

 o getAddress()
Returns the IP address of the machine to which this datagram is being sent or from which the datagram was received.
 o getData()
Returns the data received or the data to be sent.
 o getLength()
Returns the length of the data to be sent or the length of the data received.
 o getPort()
Returns the port number on the remote host to which this datagram is being sent or from which the datagram was received.
 o setAddress(InetAddress)
 o setData(byte[])
 o setLength(int)
 o setPort(int)

Constructors

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

Methods

 o 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.
See Also:
InetAddress
 o 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.
 o getData
public synchronized byte[] getData()
Returns the data received or the data to be sent.

Returns:
the data received or the data to be sent.
 o 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.
 o setAddress
public synchronized void setAddress(InetAddress iaddr)
 o setPort
public synchronized void setPort(int iport)
 o setData
public synchronized void setData(byte ibuf[])
 o setLength
public synchronized void setLength(int ilength)

All Packages  Class Hierarchy  This Package  Previous  Next  Index

Submit a bug or feature - Version 1.1.8 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1995-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.