Package java.net Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class DatagramPacket

Constructors , Methods

public  final  class  java.net.DatagramPacket
    extends  java.lang.Object  
{
        // Constructors
    public DatagramPacket(byte  ibuf[], int  ilength);	
    public DatagramPacket(byte  ibuf[], int  ilength,	
                              InetAddress  iaddr, int iport);

        // Methods
    public InetAddress getAddress();	
    public byte[] getData();	
    public int getLength();	
    public int getPort();	
}

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.


Constructors


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

ParameterDescription
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

ParameterDescription
ibuf the packet data
ilength the packet length
iaddr the desination address(§4.4)
iport the destination port number


Methods


getAddress

public InetAddress getAddress() 

Return Value:

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


getData

public byte[] getData() 

Return Value:

Returns the data received, or the data to be sent.


getLength

public int getLength() 

Return Value:

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


getPort

public int getPort() 

Return Value:

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



Top© 1996 Sun Microsystems, Inc. All rights reserved.