0

I'm reading through my textbook and I see this:

The first constructor:

public Datagrampacket (byte ibuf [], int ilength)

constructs a DatagramPacket for receiving packets of length ilength.

Is this just an odd wording, or do DatagramPacket's actually receive data along with sending it? I always thought DatagramPackets were just classes containing information you would send between DatagramSockets

Hoser
  • 4,974
  • 9
  • 45
  • 66

2 Answers2

1

DatagramPacket does not send or receive data. Instead, it is used by by DataSocket in two ways.

  • It is used by DatagramSocket.receive(DatagramPacket packet) which populates packet with some received data,
  • or it is used by DatagramSocket.send(DatagramPacket packet) to send the data contained in packet.

Hope this helps.

mjshaw
  • 401
  • 2
  • 7
0

Check the Javadoc. DatagramPackets are used for both sending and receiving. See DatagramSocket.receive().

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Maybe I'm just getting confused by some of the wording in this book. Is there any kind of relationship between DatagramPackets and DatagramSockets? Do they work together at all? Or are they totally different ways of sending and receiving data. – Hoser Feb 24 '13 at 21:00
  • @Hoser When you have read the Javadoc I suggested you read, the answer will be immediately apparent to you. – user207421 Feb 24 '13 at 21:02