com.esotericsoftware.kryonet.Client Java Examples
The following examples show how to use
com.esotericsoftware.kryonet.Client.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StateProcessor.java From killingspree with MIT License | 6 votes |
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(); }
Example #2
Source File: WorldRenderer.java From killingspree with MIT License | 6 votes |
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; }
Example #3
Source File: ClientDiscoveryScreen.java From killingspree with MIT License | 6 votes |
@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; }
Example #4
Source File: GameScreen.java From killingspree with MIT License | 6 votes |
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; }
Example #5
Source File: ClientConnector.java From RuinsOfRevenge with MIT License | 6 votes |
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); } }); }
Example #6
Source File: LobbyScreen.java From killingspree with MIT License | 5 votes |
public void setServer(boolean isServer) { this.isServer = isServer; try { if (isServer) { server = new Server(); NetworkRegisterer.register(server); serverListener = new LobbyServerListener(); server.addListener(serverListener); server.start(); server.bind(Constants.DISCOVERY_TCP_PORT, Constants.DISCOVERY_UDP_PORT); // Thread.currentThread().sleep(200); } client = new Client(); NetworkRegisterer.register(client); client.start(); clientListener = new LobbyClientListener(); client.addListener(clientListener); client.connect(5000, host, Constants.DISCOVERY_TCP_PORT, Constants.DISCOVERY_UDP_PORT); } catch (Exception e) { currentButton = backButton; markForDispose = true; e.printStackTrace(); } addAllButtons(); }
Example #7
Source File: NetClient.java From gdx-proto with Apache License 2.0 | 5 votes |
public NetClient() { client = new Client(NetManager.writeBufferSize, NetManager.objectBufferSize); client.addListener(createListener()); NetManager.registerKryoClasses(client.getKryo()); client.start(); connect(); }
Example #8
Source File: RemoteMinecraft.java From AMIDST with GNU General Public License v3.0 | 5 votes |
public RemoteMinecraft(String address) { client = new Client(65536, 65536); Kryo kryo = client.getKryo(); kryo.register(NetCreateWorldRequest.class); kryo.register(NetGetBiomeDataRequest.class); kryo.register(NetGetBiomeDataResult.class); kryo.register(NetBiome.class); kryo.register(NetBiome[].class); kryo.register(NetInfoRequest.class); kryo.register(int[].class); client.addListener(new Listener() { @Override public void received(Connection connection, Object object) { if (object instanceof NetGetBiomeDataResult) { currentResults = (NetGetBiomeDataResult)object; //Log.i("Received NetGetBiomeDataResult: " + currentResults); } else if (object instanceof NetBiome[]) { NetBiome[] biomes = (NetBiome[])object; for (int i = 0; i < biomes.length; i++) { if (biomes[i] != null) { new Biome(biomes[i].name, biomes[i].id, biomes[i].color | 0xFF000000, true); } } } } }); client.start(); try { client.connect(5000, address, 54580, 54580); } catch (IOException e) { e.printStackTrace(); } client.sendTCP(new NetInfoRequest()); }
Example #9
Source File: BenchClient.java From rpc-bench with Apache License 2.0 | 4 votes |
public BenchClient() { client = new Client(); }
Example #10
Source File: ChatRmiClient.java From kryonet with BSD 3-Clause "New" or "Revised" License | 4 votes |
public ChatRmiClient () { client = new Client(); client.start(); // Register the classes that will be sent over the network. Network.register(client); // Get the Player on the other end of the connection. // This allows the client to call methods on the server. player = ObjectSpace.getRemoteObject(client, Network.PLAYER, IPlayer.class); client.addListener(new Listener() { public void disconnected (Connection connection) { EventQueue.invokeLater(new Runnable() { public void run () { // Closing the frame calls the close listener which will stop the client's update thread. chatFrame.dispose(); } }); } }); // Request the host from the user. String input = (String)JOptionPane.showInputDialog(null, "Host:", "Connect to chat server", JOptionPane.QUESTION_MESSAGE, null, null, "localhost"); if (input == null || input.trim().length() == 0) System.exit(1); final String host = input.trim(); // Request the user's name. input = (String)JOptionPane.showInputDialog(null, "Name:", "Connect to chat server", JOptionPane.QUESTION_MESSAGE, null, null, "Test"); if (input == null || input.trim().length() == 0) System.exit(1); final String name = input.trim(); // The chat frame contains all the Swing stuff. chatFrame = new ChatFrame(host); // Register the chat frame so the server can call methods on it. new ObjectSpace(client).register(Network.CHAT_FRAME, chatFrame); // This listener is called when the send button is clicked. chatFrame.setSendListener(new Runnable() { public void run () { player.sendMessage(chatFrame.getSendText()); } }); // This listener is called when the chat window is closed. chatFrame.setCloseListener(new Runnable() { public void run () { client.stop(); } }); chatFrame.setVisible(true); // We'll do the connect on a new thread so the ChatFrame can show a progress bar. // Connecting to localhost is usually so fast you won't see the progress bar. new Thread("Connect") { public void run () { try { client.connect(5000, host, Network.port); // Server communication after connection can go here, or in Listener#connected(). player.registerName(name); } catch (IOException ex) { ex.printStackTrace(); System.exit(1); } } }.start(); }
Example #11
Source File: ClientConnector.java From RuinsOfRevenge with MIT License | 4 votes |
public Client getClient() { return client; }