While working on a WebSocket server in Java, I came across this strange error. I reduced it to two small java files, one of them is a server, the other is a client. The client simply sends 0x00 , the string Hello , and then 0xFF (according to the WebSocket specification).
On my Windows machine, the server prints the following:
Listening byte: 0 72 101 108 108 111 recieved: 'Hello'
In my unix block, the same code prints the following:
Listening byte: 0 72 101 108 108 111 -3
Instead of accepting 0xFF, it gets -3, never exits the loop, and never prints what it received.
The important part of the code looks like this:
byte b = (byte)in.read(); System.out.println("byte: "+b); StringBuilder input = new StringBuilder(); b = (byte)in.read(); while((b & 0xFF) != 0xFF){ input.append((char)b); System.out.print(b+" "); b = (byte)in.read(); } inputLine = input.toString(); System.out.println("recieved: '" + inputLine+"'"); if(inputLine.equals("bye")){ break; }
I also uploaded two files to my server:
My Windows computer is running Windows 7, and Debian is running on my Linux machine
Edit:
When b is int, it still acts weird. I send 0xFF (255), but I get 65533 (not 65535 or 255).
source share