Take at look at datagrams. Specificially, there is a DatagramSocket class. There is also a DatagramPacket class. The DatagramPacket has methods for setting the size of a packet for packets sent (outgoing). To receive packets, you have to specify the maximum allowed packet size. You'd have to write the specifics for tracking total bytes received for example, but it should be easily done based on the methods available (e.g. getlength(), getData() ). The problem with datagrams is that they do not guarantee delivery. Packets can arrive out of sequence or not at all.
Good luck! A google search on java.net DatagramPacket should give you more details.
Here's a good place to start:
http://java.sun.com/j2se/1.4.2/docs/...ramPacket.html