    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.

##

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

##

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

##

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

##

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

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.

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.

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.

setAddress

     public synchronized void setAddress(InetAddress iaddr)

setPort

     public synchronized void setPort(int iport)

setData

     public synchronized void setData(byte ibuf[])

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.