split - Java help to convert UDP packet to int -
i'm receiving udp packet (in format don't know, think utf-16 -little endian-), thing know next doc. straight developers page:
the master servers each respond sending ff ff ff ff 73 0a followed (relatively) unique 4-byte "challenge" number.
so how i'm receiving packet:
byte[] buff = new byte[64]; datagrampacket packet = new datagrampacket(buff, buff.length); socket.receive(packet);
packet received, okay, i'm stuck. need 4 byte integer. must split buffer or... don't know do.
this received data:
˙˙˙˙s Ň?t
i tried convert hex output interesting:
-0000000000000000000000000008cf52df7c08c
method convert:
public string tohex(string arg) throws unsupportedencodingexception { homecoming string.format("%040x", new biginteger(arg.getbytes("utf-16le"))); }
than tried convert hex string (from method above) , result much more interesting (sorry can't re-create paste, goes wrong), anyway method used convert hex string is:
public string hextostring(string hex){ stringbuilder output = new stringbuilder(); (int = 0; < hex.length(); i+=2) { string str = hex.substring(i, i+2); output.append((char)integer.parseint(str, 16)); } homecoming new string(output); }
so said, i'm stuck. don't know supposed do. need split udp packet in pieces or...?
i'm receiving udp packet (in format don't know, think utf-16 -little endian-), thing know next doc.
you need find out packet contains. packet contents have posted in question don't create much sense me, , don't seem correspond supposed format.
start out dumping bytes of byte array this:
byte[] bytes = ... int len = // number of bytes read. (int = 0; < len; i++) { system.out.format("%02x ", bytes[i]); }
then compare expected format documentation. if match (more or less) can start on problem of deciding how extract info need. otherwise, first need figure out format is. maybe can help ... need reliable rendering of packet (e.g. produced above.)
fwiw, reason getting -0000000000000000000000000008cf52df7c08c
(i think) biginteger(byte[])
interpreting byte array signed number. way, that's not way this. udp packet body sequence of bytes, not number.
i think unlikely udp packet utf-16. ffff described in official unicode code charts:
noncharacters:
these codes intended process-internal uses, not permitted interchange. [...]
ffff : • value ffff guaranteed not unicode character @ all
so if claiming utf-16, usage violating unicode standard.
java split udp
No comments:
Post a Comment