com.esotericsoftware.kryonet.Listener Java Examples
The following examples show how to use
com.esotericsoftware.kryonet.Listener.
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: WorldManager.java From killingspree with MIT License | 5 votes |
private void processEvents(Listener listener, ArrayList<Event> queue) { for (Event event: queue) { if (event.state == State.CONNECTED) { listener.connected(dummyConnection); } else if (event.state == State.RECEIVED) { listener.received(dummyConnection, event.object); } else if (event.state == State.DISCONNECTED) { listener.disconnected(dummyConnection); } } queue.clear(); }
Example #2
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 #3
Source File: WorldManager.java From killingspree with MIT License | 4 votes |
public void setOutgoingEventListener(Listener listener) { outgoingEventListener = listener; }
Example #4
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(); }