I need to send a short order to a network server, which I write using Java. I read about network order, but I could not find details about the short one that is sent before the data. Can someone explain to me what it is and how to send it to a client with Java?
Java NIO byte buffers support byte ordering. Thus, the network byte order is a large endian.
// Allocate a big endian byte buffer ByteBuffer bb = ByteBuffer.allocate(4096); bb.order(ByteOrder.BIG_ENDIAN); bb.putShort(12345); // Write the buffer to an NIO channel bb.flip(); channel.write(bb);
Byte order is the order in which bytes are stored for numeric values ββthat are more than one byte. There are 2 flavors Big Endian (high byte) and Little Endian (low low byte).
java int - 2 . , .., . OutputStream o short i,
OutputStream o
short i
o.write((i >> 8) & 0xff); o.write(i & 0xff);
. DataOutputStream, writeShort() ( writeInt, writeLong ..), .
DataOutputStream
writeShort()
writeInt
writeLong
OutputStream DataOutputStream.
DataOutputStream.writeShort. .
Source: https://habr.com/ru/post/1727102/More articles:spl_autoload does not work when the script is run from the command line - phpHow to create a UITextView with a three-dimensional shadow border? - coding-styleRecompile Vim for pythoncomplete # Fill in the modules * other * than the standard library? - pythonOpening a file with the appropriate program - winapiLanguages ββwith direct compatibility C - c ++Can we "not override a specific method ..." compile a temporary error in the implementation of the interfaces? - javaHow to write the right static methods - multithreaded safe - multithreadingCSS selector style - cssCustom Validation Messages for Authlogic Session Model - ruby-on-railshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1727107/what-happens-to-unicode-in-a-systemdatasqlcommand&usg=ALkJrhhvo1_b43zIY6I6RCYPwp0YeJukXQAll Articles