Packages This Package Prev Next Index
§4.2 Class DatagramPacket
public final class java.net.DatagramPacket
extends java.lang.Object (I-§1.12)
{
// Constructors
public DatagramPacket(byte ibuf[], int ilength); §4.2.1
public DatagramPacket(byte ibuf[], int ilength, §4.2.2
InetAddress iaddr, int iport);
// Methods
public InetAddress getAddress(); §4.2.3
public byte[] getData(); §4.2.4
public int getLength(); §4.2.5
public int getPort(); §4.2.6
}
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 a machine to another might be routed differently, and might arrive in any order.
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 DatagramPacket 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 desination address(§4.4)
iport
-
the destination port number
getAddress
public InetAddress getAddress()
- Returns:
- the IP address (§4.4) of the machine 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.
getLength
public int getLength()
- Returns:
- the length of the data to be sent, or the length of the data received.
getPort
public int getPort()
- Returns:
- the port number on the remote host to which this datagram is being
sent, or from which the dagram was received.
Packages This Package Prev Next Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to doug.kramer@sun.com