Package net.yura.lobby.quickserver

Source Code of net.yura.lobby.quickserver.BinaryHandler

/*
* This file is part of the QuickServer library
* Copyright (C) 2003-2005 QuickServer.org
*
* Use, modification, copying and distribution of this software is subject to
* the terms and conditions of the GNU Lesser General Public License.
* You should have received a copy of the GNU LGP License along with this
* library; if not, you can download a copy from <http://www.quickserver.org/>.
*
* For questions, suggestions, bug-reports, enhancement-requests etc.
* visit http://www.quickserver.org
*
*/

package net.yura.lobby.quickserver;

import java.io.IOException;
import java.net.SocketTimeoutException;
import net.yura.lobby.model.Message;
import net.yura.lobby.server.LobbyServer;
import net.yura.lobby.server.LobbySession;
import org.quickserver.net.server.ClientBinaryHandler;
import org.quickserver.net.server.ClientHandler;

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;
            }
        }
    }
   
    private void handleMessage(ClientHandler ch, Message message) {
       
        LobbyServer server = ((Server)ch.getServer()).lobbyServer;
        LobbySession session = ((Session)ch.getClientData()).lobbySession;
       
        server.handleMessage(session,message);
    }

}
TOP

Related Classes of net.yura.lobby.quickserver.BinaryHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.