Android
java.net
public final class

java.net.DatagramPacket

java.lang.Object
java.net.DatagramPacket

This class models a datagram packet to be sent or received. The DatagramPacket(byte[], int, InetAddress, int) constructor is used for packets to be sent, while the DatagramPacket(byte[], int) constructor is used for received packets.

See Also

Summary

Public Constructors

            DatagramPacket(byte[] data, int length)
Constructs a new DatagramPacket suitable for receiving datagram packets of length up to length.
            DatagramPacket(byte[] data, int offset, int length)
Constructs a new DatagramPacket suitable for receiving datagram packets of length up to length, with an offset into the buffer offset.
            DatagramPacket(byte[] data, int offset, int length, InetAddress host, int aPort)
Constructs a new DatagramPacket suitable for sending packets to the nominated host/port.
            DatagramPacket(byte[] data, int length, InetAddress host, int port)
Constructs a new DatagramPacket suitable for sending packets to the nominated host/port.
            DatagramPacket(byte[] data, int length, SocketAddress sockAddr)
Constructs a new DatagramPacket suitable for sending packets to the nominated host/port.
            DatagramPacket(byte[] data, int offset, int length, SocketAddress sockAddr)
Constructs a new DatagramPacket suitable for sending packets to the nominated host/port.

Public Methods

  synchronized        InetAddress  getAddress()
Answer the IP address of the machine that is the target or sender of this datagram.
  synchronized        byte[]  getData()
Answer the data sent or received in this datagram.
  synchronized        int  getLength()
Answer the length of the data sent or received in this datagram.
  synchronized        int  getOffset()
Answer the offset of the data sent or received in this datagram buffer.
  synchronized        int  getPort()
Answer the port number of the target or sender machine of this datagram.
  synchronized        SocketAddress  getSocketAddress()
Answer the SocketAddress for this packet.
  synchronized        void  setAddress(InetAddress addr)
Set the IP address of the machine that is the target of this datagram.
  synchronized        void  setData(byte[] buf, int anOffset, int aLength)
Set the data buffer for this datagram.
  synchronized        void  setData(byte[] buf)
Set the data sent in this datagram.
  synchronized        void  setLength(int len)
Set the length of the data sent in this datagram.
  synchronized        void  setPort(int aPort)
Set the port number of the target machine of this datagram.
  synchronized        void  setSocketAddress(SocketAddress sockAddr)
Set the SocketAddress for this packet.
Methods inherited from class java.lang.Object

Details

Public Constructors

public DatagramPacket(byte[] data, int length)

Constructs a new DatagramPacket suitable for receiving datagram packets of length up to length.

Parameters

data byte array to store the read characters
length length of the data buffer

public DatagramPacket(byte[] data, int offset, int length)

Constructs a new DatagramPacket suitable for receiving datagram packets of length up to length, with an offset into the buffer offset.

Parameters

data byte array to store the read characters
offset the offset into the byte array
length length of the data buffer

public DatagramPacket(byte[] data, int offset, int length, InetAddress host, int aPort)

Constructs a new DatagramPacket suitable for sending packets to the nominated host/port. The length must be less than or equal to the size of data.

Parameters

data byte array to store the read characters
offset the offset in to read/write from
length length of the data buffer
host address of the target host
aPort target host port

public DatagramPacket(byte[] data, int length, InetAddress host, int port)

Constructs a new DatagramPacket suitable for sending packets to the nominated host/port. The length must be less than or equal to the size of data.

Parameters

data byte array to store the read characters
length length of the data buffer
host address of the target host
port target host port

public DatagramPacket(byte[] data, int length, SocketAddress sockAddr)

Constructs a new DatagramPacket suitable for sending packets to the nominated host/port. The length must be less than or equal to the size of data.

Parameters

data byte array to store the read characters
length length of the data buffer
sockAddr the machine address and port

public DatagramPacket(byte[] data, int offset, int length, SocketAddress sockAddr)

Constructs a new DatagramPacket suitable for sending packets to the nominated host/port. The length must be less than or equal to the size of data.

Parameters

data byte array to store the read characters
offset the offset in to read/write from
length length of the data buffer
sockAddr the machine address and port

Public Methods

public synchronized InetAddress getAddress()

Answer the IP address of the machine that is the target or sender of this datagram.

Returns

  • InetAddress the target host address

public synchronized byte[] getData()

Answer the data sent or received in this datagram.

Returns

  • byte[] the data sent/received

public synchronized int getLength()

Answer the length of the data sent or received in this datagram.

Returns

  • int the length of the sent/received data

public synchronized int getOffset()

Answer the offset of the data sent or received in this datagram buffer.

Returns

  • int the offset of the start of the sent/received data

public synchronized int getPort()

Answer the port number of the target or sender machine of this datagram.

Returns

  • int for received packets, the sender address and for sent packets, the target host

public synchronized SocketAddress getSocketAddress()

Answer the SocketAddress for this packet.

public synchronized void setAddress(InetAddress addr)

Set the IP address of the machine that is the target of this datagram.

Parameters

addr the target host address

public synchronized void setData(byte[] buf, int anOffset, int aLength)

Set the data buffer for this datagram.

Parameters

buf the data to be sent
anOffset the offset into the data
aLength the length of the data to be sent

public synchronized void setData(byte[] buf)

Set the data sent in this datagram.

Parameters

buf the data to be sent

public synchronized void setLength(int len)

Set the length of the data sent in this datagram.

Parameters

len the length of the data to be sent

public synchronized void setPort(int aPort)

Set the port number of the target machine of this datagram.

Parameters

aPort the target host port

public synchronized void setSocketAddress(SocketAddress sockAddr)

Set the SocketAddress for this packet.

Parameters

sockAddr the machine address and port
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48