Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Byte Network Socket  RSS feed

 
Abu Nene
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I'm wondering is it a good idea to send data in byte using the network socket so to save the network packet?

For eg. if I were to send "abc123456.789"? Should I convert the 123456.789 to byte representation first instead as char array before sending?

Correct me if I'm wrong, I understand there could be possible information lost for this conversion if the compiler is using different bit for the same type.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java supports lots of methods for converting objects and primatives to and from byte[] so it is certainly possible to avoid sending characters which have to be converted.

I would only recommend packing data into byte[] for socket transmission IF you are expecting very high data rates or have a very slow connection. Its just too much chance for bugs and errors for too little gain.

See javadocs for java.lang.Double class for discussion of formal representation of floating point numbers.

If you have Java on both ends, serializing objects is remarkably fast and simple.

Bill
 
Abu Nene
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi William, got it. Thanks for your reply.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!