Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Whats the fastest way?  RSS feed

 
rob adobadob
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the fastest way of sending bytes from a file over the network in UDP packets? This is my guess, but it still seems quite slow. Any better ideas?

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know anything faster but I would like to point out that if your input byte count does not come out even with your buffer size, your last buffer sent will be incorrect. See the setLength() method to fix this.
Bill
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect NIO classes may give better results here (though that's never guaranteed). Try using a FileChannel and DatagramChannel, using the transferTo() method on FileChannel. Note that you probably need to run this in a loop (checking the return value) to ensure all bytes are transferred.

Also, whether you use traditional IO or NIO, you may want to experiment with different parameters, such as buffer size, just to see if there's a substantial effect.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!