Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. // вот метод отправки в службе:
  2.  
  3. private void sendPacket(String reply, byte[] data) throws IOException {
  4. try {
  5. Log.logger.trace(this + "< " + reply + "; data.length = " + data.length);
  6. byte[] str = reply.getBytes(encodeCash);
  7. byte[] buf = new byte[1 + str.length + data.length + 8];
  8. buf[0 + 8] = (byte) str.length;
  9. System.arraycopy(str, 0, buf, 1 + 8, str.length);
  10. System.arraycopy(data, 0, buf, 1 + 8 + str.length, data.length);
  11. int size = buf.length - 4;
  12. buf[3] = (byte) (size & 0xff);
  13. buf[2] = (byte) ((size >> 8) & 0xff);
  14. buf[1] = (byte) ((size >> 16) & 0xff);
  15. buf[0] = (byte) ((size >> 24) & 0xff);
  16. buf[7] = (byte) (version & 0xff);
  17. buf[6] = (byte) ((version >> 8) & 0xff);
  18. buf[5] = (byte) ((version >> 16) & 0xff);
  19. buf[4] = (byte) ((version >> 24) & 0xff);
  20.  
  21. bos.write(buf);
  22. bos.flush();
  23. os.flush();
  24.  
  25. Log.logger.trace(this + "SendPacket - Ok");
  26.  
  27. } catch (IOException e) {
  28. throw e;
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement