Answer the question
In order to leave comments, you need to log in
How to pass a byte through getOutputStream()?
There is a byte and a websocket connection.
I'm trying to send a byte in a message like this:
byte newByte = 11;
newByte = 11;
client.getOutputStream().write(newByte);
client.getOutputStream().write(("0").getBytes());
Answer the question
In order to leave comments, you need to log in
That's right, OutputStream.write() takes an array of bytes, which String.getBytes() just returns. To pass one byte, you need to pass an array of one element to the write method:
Only the design remained incomprehensible to me . If you need to declare a variable containing one byte, then it should look like this:byte newByte = new newByte;
byte b = 11;
There was a typo in the design, I need to transfer an array of bytes, but I didn’t succeed and I started trying to transfer bytes.
It fails to send:
byte newByte = 11;
client.getOutputStream().write(new byte[] {newByte});
byte[] newByte = new byte[1];
newByte[0] = 11;
client.getOutputStream().write(newByte);
newByte[0] = 0xffffffcf;
byte[] newByte = new byte[1];
newByte = ("11").getBytes();
client.getOutputStream().write(newByte);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question