Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 0.63 KB  |  hits: 33  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Send packet over UDP socket
  2. static int user_id; // 4 Bytes
  3. static byte state;  // 1 Byte
  4. static String cipher_data; // 128 Bytes
  5. static String hash;  // 128 Bytes
  6.  
  7. static final int PACKET_SIZE = 261;
  8.  
  9. public static byte [] packet = new byte [PACKET_SIZE];
  10.        
  11. ByteArrayOutputStream baos = new ByteArrayOutputStream(PACKET_SIZE);
  12. DataOutputStream dos = new DataOutputStream(baos);
  13. dos.write(state);
  14. dos.writeInt(user_id);
  15. for (int i = 0; i < cipher_data.length(); i++) {
  16.     dos.write((byte) cipher_data.charAt(i));
  17. }
  18. for (int i = 0; i < cipher_data.length(); i++) {
  19.     dos.write((byte) hash.charAt(i));
  20. }
  21. packet = baos.toByteArray();