The abstract class DatagramSocketImpl has two methods.
int peek(InetAddress)
and
int peek(DatagramPacket)
Does anyone know what exactly this methods do? What are they for?
I can't find any documentation about them. The javadoc says:
for the first
Peek at the packet to see who it is from.
for the second
Peek at the packet to see who it is from. The data is returned, but not
consumed, so that a subsequent peekData/receive operation will see the
same data.
So they peek a look at the first available received packet of a socket
but leave it there to be received from the Application that uses the
DatagramSocket.
I managed to find that the integer that tey return is the source port of
the received datagram.
But, for the first method, how does it return the InetAddress of the
sender of the packet? The InetAddress class does not provide any set
methods. The same for the second method. How does it return the datagram?
> The abstract class DatagramSocketImpl has two methods.
> int peek(InetAddress)
> and
> int peek(DatagramPacket)
That should read
int peekData(DatagramPacket)
> Does anyone know what exactly this methods do? What are they for?
>
[quoted text clipped - 5 lines]
> consumed, so that a subsequent peekData/receive operation will see the same
> data.
So you could find some documentation.
> So they peek a look at the first available received packet of a socket but
> leave it there to be received from the Application that uses the
> DatagramSocket.
I suppose so.
> I managed to find that the integer that tey return is the source port of the
> received datagram.
Well, there you have it.
> But, for the first method, how does it return the InetAddress of the sender
> of the packet? The InetAddress class does not provide any set methods. The
> same for the second method. How does it return the datagram?
It doesn't return an InetAddress, it returns an int, just like the second
method. Supposedly, the first method looks up the last packet received from
the specified address and returns it's source port.