My goal is to decode message, sent by a client to the server through the WebSocket connection. The frame data have length, more on Base Framing Protocol [RFC6455].
I recently found out that read(byte[] b)
outputs the entire frame.
For example, when a client send message abcdef
to the server
byte[] frame = new byte[1000]
inputStream.read(frame); // [[-127, -122, -69, -122, 95, -5, -38, -28, 60, -97, -34, -32, 0, 0, ....]
However, the first byte should be 129
and the second byte should be 134
. Is the only way to read the frame is through loop and use int[]
instead of byte[]
since the read()
method outputs int instead of byte?
int[] frame = new frame[1000];
booean close = false;
frame[0] = inputStream.read();
frame[1] = inputStream.read();
int length = frame[1] & 127;
int pointer = 2;
while (!close) {
frame[pointer] = inputStream.read();
if (pointer == length) {
close = true;
}
}