WebSocketFrame readResult;
do {
readResult = WebSocketFrame.readFrame(in);
if (readResult.bytesRead == -1) { return -1; }
if (readResult.masked == false) {
throw new WebSocketException("Received an unmasked frame from client.");
}
if (readResult.opcode == 0x8) {
throw new WebSocketException("The opposite side closed the WebSocket connection.");
}
ping = readResult.opcode == 0x9;
if (ping) {
//automatically form ping response (pong)
byte[] appData = readResult.bytes;