Note that there are some explanatory texts on larger screens.

plurals
  1. POJava help to convert UDP packet to int
    primarykey
    data
    text
    <p>I'm receiving an UDP packet (in which format I don't know, I think UTF-16 -little endian-), only thing that I know is the following doc. directly from the developers page:</p> <blockquote> <p>The master servers each respond by sending FF FF FF FF 73 0A followed by a (relatively) unique 4-byte "challenge" number.</p> </blockquote> <p>So this is how I'm receiving the packet:</p> <pre><code>byte[] buff = new byte[64]; DatagramPacket packet = new DatagramPacket(buff, buff.length); socket.receive(packet); </code></pre> <p>Packet was received, everything is Okay, but now I'm stuck. I need that 4 byte integer. I must split the buffer or... I don't know what to do.</p> <p>This is the received data:</p> <pre><code>˙˙˙˙s Ň?t </code></pre> <p>I tried to convert to hex but the output is very interesting:</p> <blockquote> <p>-0000000000000000000000000008cf52df7c08c</p> </blockquote> <p>Method to convert:</p> <pre><code>public String toHex(String arg) throws UnsupportedEncodingException { return String.format("%040x", new BigInteger(arg.getBytes("UTF-16LE"))); } </code></pre> <p>Than I tried to convert hex to string (from the method above) and the result is much more interesting (sorry I can't copy paste, something goes wrong), anyway the method used to convert hex to string is:</p> <pre><code>public String hexToString(String hex){ StringBuilder output = new StringBuilder(); for (int i = 0; i &lt; hex.length(); i+=2) { String str = hex.substring(i, i+2); output.append((char)Integer.parseInt(str, 16)); } return new String(output); } </code></pre> <p>So with all that said, I'm stuck. I don't know what am I supposed to do. Am I need to split the UDP packet in to pieces or...?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload