I have a question for you: is there a way to count the number of
packets going through a stream? I know data is sent byte by byte
through a stream socket, but how can i count the actual number of
packets?
"streams" are conceptually not "packets", which exist at a lower layer
in the protocol stack.
At any rate Java doesn't provide any way to determine this.
However you can make a rough guess if you know the MTU for the network
(usually 1500 bytes for ethernet, but ifconfig can tell you for sure).
Determine the lower bound by counting the total bytes sent, and
dividing by the MTU. This assumes that every IP datagram is completely
filled.
Determine the upper bound by doing the same calculation individually
for every call to OutputStream.write(n bytes), rounding *up* whenever
n is not an exact multiple of MTU, since the extra bytes will require
an additional packet.
Depending on sender timing and other issues, the real answer will lie
somewhere between the two bounds, but likely closer to the upper
bound.
/gordon