• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Bear Bibeault
  • paul wheaton
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Mikalai Zaikin
  • Piet Souris
Bartenders:

UDP issues

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all. Im writing a server for a multiplayer game. Information is sent in packets of 256 bytes. The first 4 bytes of each packet is an integer number representing the ID of this packet. When a packet is send a local copy is stored in a hashmap based on the integer ID. When the server recieves a packet out of sequence it requests a resend of the packet its been expecting which is taken from the hashmap and resent.

The problem is that for certain numbers the id comes out wrong and I cant work out why.



One example is for 144. The id is 144, it gets put into the byte array and stored int the hashmap and send. The local copy in the hashmap and the message sent to the server come out as 63. Does anyone have any idea why it might do this?

thanks
Brendan
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm going to gout on a limb here and say 144 is beyond the value of a byte?

Recently, in my company we were working on a program that reads a barcode value and decodes it, we run our program on two platforms, one for linux and one for windows and we noticed something strange. The barcode we were reading is referred to using hex values and as such we had one with the hexvalue of 0x81 .. of course 81 is beyond the limits of a byte and will be a negative value in byte which is fine..

The strange thing is how a byte is read by a String class. In Windows the value we entered returned as 63 or a "?" and in Linux it returned as blank. This really only happened after we convert the byte array into a string as we tested the byte array and the values are correct, though negative for values exceeding 127.

In short, negative byte values do not get translated correctly when passed into a String. I think this has to do with the fact that the ascii chart generally reaches to 127 and anything beyond that is platform dependent? Occasionally with negative byte values i get some weird Strings not in the standard ascii char set.

What you can perhaps do is before using it as a hash key is to convert it into a positive short or int value.. thats what we did and might not be the best way to do it

I hope this helps.

Regards

p/s : Sorry if i am not clear, i'm hopeless in explaining things...
[ September 22, 2006: Message edited by: Darren Cheong ]
 
You’ll find me in my office. I’ll probably be drinking. And reading this tiny ad.
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic