public class BinaryHandler implements ClientBinaryHandler {
@Override
public void handleBinary(ClientHandler ch, byte[] bytes) throws SocketTimeoutException, IOException {
LobbyServer server = ((Server)ch.getServer()).lobbyServer;
Session cd = (Session)ch.getClientData();
cd.data.addBytes(bytes);
while (true) {
if (cd.size==-1 && cd.data.available() >= 4) {
cd.size = cd.data.readInt();
}
else if (cd.size>=0 && cd.data.available() >= cd.size) {
Message message = server.decode(cd.data, cd.size);
cd.size = -1;
handleMessage(ch, message);
}
else {
break;