Java 类com.esotericsoftware.kryonet.Client 实例源码

项目:mindroid    文件:EV3Brick.java   
/**
 * Creates a Brick Class.
 *
 * @param ev3Brick_IP
 * @param ev3Brick_PORT
    */
public EV3Brick (final String ev3Brick_IP, int ev3Brick_PORT) {
       this.EV3Brick_IP = ev3Brick_IP;
       this.EV3Brick_PORT = ev3Brick_PORT;

       motorManager     = new EV3MotorManager(this); //TODO
       sensorManager    = new EV3SensorManager(this);

    System.out.println("Local-EV3Brick: Starte client.. ");
    client = new Client();
    client.start();
    new Thread(client).start(); //Neccessary to keep connection alive!

    /** Add Listeners to Client **/
    client.addListener(this);
    client.addListener(sensorManager);
    client.addListener(motorManager);

    //Set Client to Motor-/Sensormanager
    sensorManager.setBrickClient(client);
    motorManager.setBrickClient(client);

    MessageRegistrar.register(client);


   }
项目:VoiceChat    文件:VoiceChatClient.java   
/**
 * Makes this chat client process and respond to audio sent from the server. If this message is not called, you will not hear anything
 * from the server!
 * @param client The client that audio data will be sent to from the server. Just use the normal client.
 */
public void addReceiver(Client client){

    if(this.player == null)
        this.createPlayer();

    client.addListener(new Listener(){
        public void received(Connection connection, Object object) {

            // Only read objects of the correct type.
            if(object instanceof VoiceNetData){

                // Read data
                VoiceNetData message = (VoiceNetData)object;                    
                short[] data = message.getData();

                // Play audio
                processAudio(data, connection, message);
            }
        }           
    });
}
项目:octoBubbles    文件:ClientController.java   
public ClientController(AbstractDiagramController pDiagramController, String pServerIp, int pPort) {
    diagramController = pDiagramController;
    serverIp = pServerIp;
    port = pPort;

    client = new Client();

    initKryo(client.getKryo());

    client.addListener(new Listener() {
        public void received (Connection connection, Object object) {
            if (object instanceof AbstractNode) {
                Platform.runLater(() -> diagramController.createNodeView((AbstractNode)object, true));
            } else if (object instanceof AbstractEdge) {
                Platform.runLater(() -> diagramController.addEdgeView((AbstractEdge)object, true));
            } else if (object instanceof Graph){
                Graph graph = (Graph) object;
                graph.addRemotePropertyChangeListener(ClientController.this);
                Platform.runLater(() -> diagramController.load(graph, true));
            } else if (object instanceof String[]){
                Platform.runLater(() -> diagramController.remoteCommand((String[])object));
            }
        }
    });
}
项目:javatrove    文件:ClientDisconnectCommandHandler.java   
@Override
public void handle(final Client client, Connection connection, Command command) {
    model.getClient().ifPresent(c -> {
        if (c == client) {
            model.getMessages().add("Server " + model.getServer() + ":" + model.getPort() + " is no longer available.");
            client.stop();
            try {
                client.dispose();
            } catch (IOException ignored) {
                // OK
            }
            model.setClient(null);
            model.setConnected(false);
            model.getMessages().clear();
        }
    });
}
项目:Buildstation-3    文件:ClientNetworkController.java   
public ClientNetworkController() {
    while (true) {
        promptIPPort();
        client = new Client();
        client.start();
        try {
            client.connect(5000, Variables.serverIP, Variables.port);
        }
        catch (IOException e) {
            Utilities.popupMessage("BuildStation", "Invalid Input\nThe server refused the connection or an unknown error occurred.");
            e.printStackTrace();
            promptIPPort();
            continue;
        }
        client.getKryo().setRegistrationRequired(false);
        ListenerList.addListeners(client);
        break;
    }
}
项目:MMO-Rulemasters-World    文件:PacketsInterpretator.java   
public PacketsInterpretator(Client client) {
    mClient = client;
    mPackets.put(ConnectPacket.class, new ConnectAction());
    mPackets.put(ErrorPacket.class, new ErrorAction());
    mPackets.put(EntityPacket.class, new EntityAction());
    mPackets.put(EntityMovePacket.class, new EntityMoveAction());
    mPackets.put(EntityRemovePacket.class, new EntityRemoveAction());
    mPackets.put(EntityHpPacket.class, new EntityHpAction());
    mPackets.put(EntityEffectAddPacket.class, new EntityEffectAddAction());
    mPackets.put(EntityEffectRemovePacket.class, new EntityEffectRemoveAction());
    mPackets.put(NewUserConnectedLobbyPacket.class, new NewUserConnectedLobbyAction());
    mPackets.put(TchatMsgPacket.class, new TchatMsgAction());
    mPackets.put(TchatPrivmsgPacket.class, new TchatPrivmsgAction());
    mPackets.put(PlayerSpellPacket.class, new PlayerSpellAction());
    mPackets.put(PlayerSpellUsedPacket.class, new PlayerSpellUsedAction());
}
项目:killingspree    文件:StateProcessor.java   
public StateProcessor(Client client, ConcurrentHashMap<Short, ClientEntity> worldMap,
        SFXPlayer audioPlayer, PlatformServices toaster) {
    if (client != null) {
        this.client = client;
        client.addListener(this);
    }
    this.toaster = toaster;

    nextState = MessageObjectPool.instance.
            gameStateMessagePool.obtain();
    nextState.time = 0;
    stateQueue = new ArrayList<GameStateMessage>();
    wait = new AtomicBoolean(false);
    this.world = worldMap;
    disconnected = false;
    this.audioPlayer = audioPlayer;
    playerNames = new PlayerNamesMessage();
}
项目:killingspree    文件:WorldRenderer.java   
public WorldRenderer(WorldManager worldManager, Client client, KillingSpree game) {
    worldMap = new ConcurrentHashMap<Short, ClientEntity>();
    this.worldManager = worldManager;
    audioPlayer = new SFXPlayer();
    stateProcessor = new StateProcessor(client, worldMap, audioPlayer,
            game.platformServices);
    if (worldManager != null) {
        debugRenderer = new WorldDebugRenderer(worldManager.getWorld());
        worldManager.setOutgoingEventListener(stateProcessor);
    } else {
        this.client = client;
    }
    camera = new OrthographicCamera();
    batch = new SpriteBatch();
    controlsSender = new ControlsSender();
    recentId = -2;
    screenShakeX = 0;
    screenShakeY = 0;
    screenShakeTime = 0;
    hudRenderer = new HUDRenderer();
    this.game = game;
}
项目:killingspree    文件:ClientDiscoveryScreen.java   
@Override
public void show() {
    client = new Client();
    client.start();
    font = game.getFont(120);
    batch = new SpriteBatch();
    camera = new OrthographicCamera();
    viewport = new FitViewport(1280, 720, camera);
    camera.setToOrtho(false, 1280, 720);
    buttons = new ArrayList<MyButton>();
    ipAddresses = new ArrayList<MyButton>();
    markForDispose = false;
    addAllButtons();
    addIpButtons();
    pressedButton = false;
}
项目:killingspree    文件:GameScreen.java   
public boolean loadLevel(String level, String host, String name) {
    if (isServer) {
        world = new WorldManager(server);
        if (server == null)
            world.loader.platformServices = game.platformServices;
    } else {
        client = new Client();
        NetworkRegisterer.register(client);
        client.start();
        try {
            client.connect(Constants.TIMEOUT, host,
                    Constants.GAME_TCP_PORT,
                    Constants.GAME_UDP_PORT);
        } catch (IOException e) {
            game.platformServices.toast("Server not found");
            e.printStackTrace();
            game.setScreen(new ClientDiscoveryScreen(game));
            return false;
        }
    }

    renderer = new WorldRenderer(world, client, game);
    renderer.loadLevel(level, isServer, name);
    return true;
}
项目:Projet2015    文件:ClientCommunicationKryonetImpl.java   
@Override
public synchronized boolean launchClient()
{   boolean result = true;

    client = new Client(60000, 60000);
    client.start();

    firstRound = true;

    ClassRegisterer.register(client);

    client.addListener(this);

    int timeout = 5000;
    try
    {   client.connect(timeout, ip, port, port + 1);
    }
    catch (IOException e)
    {   result = false;
        e.printStackTrace();
    }

    return result;
}
项目:Shadow-of-Goritur    文件:InventoryGUI.java   
@Override
public void move(Entity item, int x, int y) {

    ArrayList<ItemContainerGroup> groups = getGroups(item, x, y);
    ItemContainerGroup group = null;
    if (groups.size() > 0) {
        group = groups.get(0);          
    } else { return; }

    x = (int) (((x-getX())/RenderingSystem.scale)/SLOTSIZE);
    y = (int) (((y-getY())/RenderingSystem.scale)/SLOTSIZE);

    if (group instanceof InventoryGUI) {
        MoveItemSimple action = new MoveItemSimple();
        action.setID(item.getComponent(CId.class));
        action.setXY(x, y);
        ((Client)AppUtil.endpoint).sendTCP(action);
    }
}
项目:Peace    文件:PeaceNetworkClient.java   
public PeaceNetworkClient()
{
    client = new Client();

    events = (Queue<PacketMessage>) new LinkedList<PacketMessage>();

    // Must register every class that will be sent/received
    client.getKryo().register(PacketMessage.class);
    client.getKryo().register(EventType.class);
    client.getKryo().register(LocationID.class);

    // Client must start before connecting can take place
    client.start();

    client.addListener(this);

    out.println("Client is now waiting..."); // TODO: remove
}
项目:ahs-invaders    文件:NetClient.java   
public NetClient(InvadersGame game, GameSetupConfig gameSetupConfig, PlayerConfig player) {
    this.game = game;
    gameConfig = gameSetupConfig;
    this.playerConfig = player;
    listeners = new Array<NetListener>();

    client = new Client();
    client.start();

    KryoCommon.register(client);

    currentListener = new ConnectListener(this);
    client.addListener(currentListener);

    connect();
}
项目:homecockpit-fsuipc    文件:FSUIPCKryonetInterface.java   
public FSUIPCKryonetInterface(String server, int port) {
    this.server = server;
    this.port = port;
    // ~
    client = new Client();
    client.start();
    client.addListener(new Listener() {
        public void received (Connection connection, Object object) {
            if(object instanceof String) {
                String message = (String)object;
                if(message.startsWith("CHANGED")) {
                    Collection<OffsetItem> offsetItems = toOffsetItems(message);
                    for(OffsetItem offsetItem : offsetItems) {
                        offsetEventListeners.fire().valueChanged(offsetItem);
                    }
                    offsetCollectionEventListeners.fire().valuesChanged(offsetItems);
                }
            }
        }
    });
    // ~
    offsetEventListeners = EventListenerSupport.create(OffsetEventListener.class);
    offsetCollectionEventListeners = EventListenerSupport.create(OffsetCollectionEventListener.class);
}
项目:ChatProgram    文件:ChatClient.java   
public ChatClient( String[] connectionDetails, ClientFrame frame ) {
    // create a new network client
    client = new Client();

    // Populate the connection details
    host = connectionDetails[0];
    name = connectionDetails[1];
    port = Network.port;

    // attach the frame
    this.frame = frame;

    //setup the client settings
    setupClient(client);

    // connect to the server
    connect();

}
项目:RuinsOfRevenge    文件:ClientConnector.java   
public ClientConnector(ClientMaster master, String host) throws IOException {
    this.master = master;
    this.client = new Client();
    this.queue = new LinkedBlockingQueue<>();
    this.newestInput = new Input();

    Register.registerAll(client.getKryo());
    new Thread(client).start();
    client.connect(5000, InetAddress.getByName(host), ServerMaster.PORT_TCP, ServerMaster.PORT_UDP);
    client.addListener(new QueuedListener(this) {
        @Override
        protected void queue(Runnable runnable) {
            queue.add(runnable);
        }
    });
}
项目:AudioRacer    文件:PlayerClient.java   
public PlayerClient() {
    super();
    _players = new HashMap<Integer, Player>();
    _cars = new HashMap<Byte, Byte>();
    _player = new Player();
    _listenerList = new PlayerClientListenerList();
    _connected = false;

    _client = new Client();
    _client.start();
    PlayerServerClient serverClient = new PlayerServerClient(_client);
    PlayerNetwork.register(_client);
    _client.addListener(serverClient);
    _client.addListener(this);
    setPlayerServer(serverClient);
}
项目:mindroid    文件:EV3SensorManager.java   
/** 
 * Checks if a Port is a valid SensorPort of the EV3Brick
 * 
 * @param
 * @return
 *//*
boolean isValidSensorPort(Port port){
    if(port == SensorPort.S1 || port == SensorPort.S2 || port == SensorPort.S3 || port == SensorPort.S4){
        return true;
    }else{
        return false;
    }       
}*/

public void setBrickClient(Client brickClient) {
    this.brickClient = brickClient;
}
项目:mindroid    文件:ClientEndpointImpl.java   
public ClientEndpointImpl(String ip,int tcpPort, int brickTimeout) {
    this.ip =ip;
    this.tcpPort = tcpPort;
    this.brickTimeout = brickTimeout;

    client = new Client();
    client.start();
    new Thread(client).start();
}
项目:VoiceChat    文件:TestGame.java   
@Override
public void create() {
    try{

        if(true){
            // Run server
            this.server = new Server(22050, 22050);
            server.bind(7777, 7777);
            server.start(); 

            relay = new VoiceChatServer(server.getKryo());

            server.addListener(new Listener(){
                public void received(Connection connection, Object object) {
                    relay.relayVoice(connection, object, server);
                }                   
            });
        }

        this.client = new Client(22050, 22050);
        client.start();
        client.connect(5000, "localhost", 7777, 7777);

        this.sender = new VoiceChatClient(client.getKryo());
        this.sender.addReceiver(client);


    }catch(Exception e){
        e.printStackTrace();
        Gdx.app.exit();
    }   


    // Other stuff for test
    batch = new SpriteBatch();
    font = new BitmapFont();
}
项目:VoiceChat    文件:VoiceChatClient.java   
/**
 * Sends what you are saying to the other connections! This method should be called whenever the client wants to send audio, 
 * such as when he/she presses a button. This method does not block at all, as recording audio is done in another thread.
 * The minimum time recorded is equal to:
 * <code>((SampleRate / SendRate) / SampleRate)</code> in seconds. The maximum time recorded is infinite.
 * @param client The client to send the data on.
 * @param delta The time, in seconds, between concurrent calls to this method.
 * If this method is called 60 times per second, this value should be (1/60). In LibGDX, use <code>Gdx.graphics.getDeltaTime()</code>.
 */
public void sendVoice(Client client, float delta){

    float interval = 1f / this.getSendRate();
    timer += delta;
    if(timer >= interval){

        if(!ready){
            timer = interval; // Keep 'on-edge'
            return;
        }
        timer -= interval;

        // Make new thread
        ready = false;
        Thread thread = new Thread(() -> {              
            // Need to check if data needs sending. TODO        
            int packetSize = (int) (this.getSampleRate() / this.getSendRate());
            if(data == null){
                data = new short[packetSize];
            }

            // This will block! We need to do this in a separate thread!
            if(this.recorder == null) this.createRecorder();
            this.recorder.read(data, 0, packetSize);

            // Send to server, this will not block but may affect networking...
            client.sendUDP(new VoiceNetData(data));

            ready = true;
        });
        thread.start();         
    }       
}
项目:MMORPG_Prototype    文件:GameClient.java   
@Override
public void create()
{
    mousePointer = Assets.get("cursor.gif"); 
    batch = Assets.getBatch();
    background = Assets.get("background.jpg");
    states = new StateManager();
    client = new Client();
    playState = new PlayState(states, client);
    client = initizlizeClient();
    states.push(playState);
    states.push(new SettingsChoosingState(client, states));
    // Gdx.input.setCursorCatched(true); 
}
项目:MMORPG_Prototype    文件:GameClient.java   
private Client initizlizeClient()
{
    Kryo kryo = client.getKryo();
    kryo = PacketsRegisterer.registerPackets(kryo);
    clientListener = new ClientListener(playState, states);
    client.addListener(clientListener);
    client.start();
    return client;
}
项目:MMORPG_Prototype    文件:RegisterationState.java   
public RegisterationState(Client client, StateManager states)
{
    this.client = client;
    this.states = states;
    dialog.show(stage);
    Gdx.input.setInputProcessor(stage);
}
项目:MMORPG_Prototype    文件:AuthenticationState.java   
public AuthenticationState(Client client, StateManager states)
{
    this.client = client;
    this.states = states;
    authenticationDialog = new AuthenticationDialog(this);
    authenticationDialog.show(stage);
    Gdx.input.setInputProcessor(stage);
    try
    {
        Thread.sleep(100);
    } catch (InterruptedException e)
    {
        e.printStackTrace();
    }
}
项目:MMORPG_Prototype    文件:SettingsChoosingState.java   
public SettingsChoosingState(Client client, StateManager states)
{
    this.client = client;
    this.states = states;
    Gdx.input.setInputProcessor(stage);

    AskForIpDialog dialog = new AskForIpDialog(this, new ConnectionInfo("localhost"));
    dialog.show(stage);
}
项目:MMORPG_Prototype    文件:ConnectionState.java   
public ConnectionState(Client client, StateManager states, ConnectionInfo connectionInfo)
{
    this.client = client;
    this.states = states;
    client.start();
    connectThread = new Thread(() -> tryConnecting(client, connectionInfo));
    connectThread.start();
}
项目:MMORPG_Prototype    文件:ConnectionState.java   
private void tryConnecting(Client client, ConnectionInfo connectionInfo)
{
    try
    {
        client.connect(3000, connectionInfo.getIp(), connectionInfo.getTcpPort(), connectionInfo.getUdpPort());
    } catch (IOException e)
    {
        currentTryout++;
        if (currentTryout < maxTryouts)
            tryConnecting(client, connectionInfo);
    }

}
项目:MMORPG_Prototype    文件:PlayState.java   
public PlayState(StateManager states, Client client)
{
    this.client = client;
    inputHandler = new NullInputHandler();
    player = new NullPlayer();
    this.states = states;
    camera.setToOrtho(false);
    camera.viewportWidth = CAMERA_WIDTH;
    camera.viewportHeight = CAMERA_HEIGHT;

    mapRenderer = new OrthogonalTiledMapRenderer(map, Assets.getBatch());
}
项目:MMORPG_Prototype    文件:ChoosingCharacterState.java   
public ChoosingCharacterState(Client client, StateManager states)
{
    this.client = client;
    this.states = states;
    creatingDialog = new CreatingCharacterDialog(this);
    GetUserCharactersPacket getUserCharactersPacket = new GetUserCharactersPacket();
    getUserCharactersPacket.username = UserInfo.username;
    client.sendTCP(getUserCharactersPacket);
}
项目:OctoUML    文件:ClientController.java   
public ClientController(AbstractDiagramController pDiagramController, String pServerIp, int pPort) {
    diagramController = pDiagramController;
    serverIp = pServerIp;
    port = pPort;

    client = new Client();

    initKryo(client.getKryo());

    client.addListener(new Listener() {
        public void received (Connection connection, Object object) {
            if (object instanceof AbstractNode) {
                Platform.runLater(() -> diagramController.createNodeView((AbstractNode)object, true));
            }
            else if (object instanceof AbstractEdge) {
                Platform.runLater(() -> diagramController.addEdgeView((AbstractEdge)object, true));
            }
            else if (object instanceof Graph){
                Graph graph = (Graph) object;
                graph.addRemotePropertyChangeListener(ClientController.this);
                Platform.runLater(() -> diagramController.load(graph, true));
            }
            else if (object instanceof String[]){
                Platform.runLater(() -> diagramController.remoteCommand((String[])object));
            }
        }
    });
}
项目:javatrove    文件:ClientProvider.java   
@Override
public Client get() {
    Client client = new Client();
    clientKryoListener.setClient(client);
    client.start();
    ChatUtil.registerClasses(client);
    client.addListener(clientKryoListener);
    return client;
}
项目:NetworkChatApplication    文件:ChatClient.java   
public void initialize() {
    username = JOptionPane.showInputDialog("Please enter a username.");
    client = new Client(25566, 25567);
    register();
    ClientListener listener = new ClientListener(this);
    client.addListener(listener);
    client.start();
}
项目:Mach3Pendant    文件:ConnectivityManager.java   
public ConnectivityManager(String accountName_, String accountType_) {
    this.accountName = accountName_;
    this.accountType = accountType_;
    tcpClient = new Client();
    udpClient = new Client();
    Network.register(tcpClient);

    setListeners();
}
项目:RavTech    文件:KryonetTransportLayer.java   
public KryonetTransportLayer (RavNetwork net) {
    super(net);
    server = new Server(bufferSize, bufferSize);
    client = new Client(bufferSize, bufferSize);

    serverListener = new ServerListener(this);
    clientListener = new ClientListener(this);

    server.addListener(serverListener);
    client.addListener(clientListener);

    register(server.getKryo());
    register(client.getKryo());
    register(streamKryo);
}
项目:CodeIT    文件:ClientController.java   
/**
 * Should be called when this scene is created, handles setup tasks.
 * @param stage The stage that this scene belongs to.
 * @param client The client that has an open connection to the server.
 * @param teamName The team name that the player has chosen.
 */
public void setup(Stage stage, Client client, String teamName) {
    this.stage = stage;
    this.client = client;
    this.team_name.setText(teamName);
    client.addListener(this);

    stage.setOnCloseRequest(event -> savePreferences());

    setServerStatus("Connected to " + client.getRemoteAddressTCP(), Color.GREEN);
    reconnect.setVisible(false);

    file_path.setText(preferences.get("file_path", System.getProperty("user.home")));
}
项目:CodeIT    文件:LoginController.java   
public void initNetwork() {
    client = new Client(Network.BUFFER_SIZE, Network.BUFFER_SIZE);

    Initializer.registerClasses(client.getKryo());
    client.addListener(this);
    clientThread = new Thread(client);
    clientThread.start();
}
项目:CodeIT    文件:RatingVisualizerController.java   
public void initNetwork() {
    client = new Client(Network.BUFFER_SIZE, Network.BUFFER_SIZE);

    Initializer.registerClasses(client.getKryo());
    client.addListener(this);
    clientThread = new Thread(client);
    clientThread.start();
    try {
        client.connect(5000, address, port);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:Buildstation-3    文件:HeadlessClientNetworkController.java   
/**
 * @throws IOException If the server refused the connection.
 */
public HeadlessClientNetworkController() throws IOException {
    client = new Client();
    client.start();
    client.connect(5000, Variables.serverIP, Variables.port);
    client.getKryo().setRegistrationRequired(false);
    ListenerList.addListeners(client);
    isHeadless = true;  // I wish I could avoid this, but for some reason, I can't override promptIPPort.
}