Reputation: 5044
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
Upvotes: 0
Views: 143
Reputation: 401
DatagramPacket
does not send or receive data. Instead, it is used by by DataSocket
in two ways.
DatagramSocket.receive(DatagramPacket packet)
which populates packet
with some received data, DatagramSocket.send(DatagramPacket packet)
to send the data contained in packet
.Hope this helps.
Upvotes: 1
Reputation: 310893
Check the Javadoc. DatagramPackets are used for both sending and receiving. See DatagramSocket.receive().
Upvotes: 0