Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Java socket programming

Thread view: 
stathis gotsis - 31 Jan 2006 01:17 GMT
Hello to everyone,
  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?
  Thank you
slippymississippi@yahoo.com - 31 Jan 2006 01:57 GMT
> Hello to everyone,
>    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?
>   Thank you

OSI 7 Layer Communications Model:

Sockets are a session library, which means that sockets reside in Layer
5.

The data is broken into packets via TCP in the Transport Layer (Layer
4) or via IP in the Network Layer (Layer 3), which are hidden from you
by sockets.

In other words, if I'm not mistaken, Java by itself can't give you this
information ... you would probably have to retrieve it from a log or a
tool somewhere.
slippymississippi@yahoo.com - 31 Jan 2006 02:06 GMT
FWIW: Java appears to support a connectionless communication protocol
via DatagramPackets over DatagramSockets.  This will allow you to count
the number of packets sent, but then you have to provide all the
functionality of TCP/IP yourself.
Gordon Beaton - 31 Jan 2006 07:47 GMT
> 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

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.