private void registerKryo() { Kryo kryo = client.getKryo(); kryo.register(java.util.ArrayList.class); kryo.register(java.util.Date.class); kryo.register(LogIn.class); kryo.register(Register.class); kryo.register(LogInSuccess.class); kryo.register(RegisterSuccess.class); kryo.register(LogInFailed.class); kryo.register(RegisterFailed.class); kryo.register(AddPlayer.class); kryo.register(RemovePlayer.class); kryo.register(CharacterClass.class); kryo.register(UserCharacter.class); kryo.register(CharacterCreateSuccess.class); kryo.register(CharacterCreateFailed.class); kryo.register(EnterWorld.class); kryo.register(PlayerPositionUpdate.class); kryo.register(MobType.class); kryo.register(MobUpdate.class); kryo.register(SnapShot.class); kryo.register(Attack.class); kryo.register(AttackStarted.class); kryo.register(MobAttack.class); kryo.register(ServerMessage.class); kryo.register(LogOut.class); kryo.register(SwitchCharacter.class); }
public void testRMI() throws IOException { Server server = new Server(); register(server.getKryo()); startEndPoint(server); server.bind(tcpPort); final ObjectSpace serverObjectSpace = new ObjectSpace(); final TestObjectImpl serverTestObject = new TestObjectImpl(4321); serverObjectSpace.register((short) 42, serverTestObject); server.addListener( new Listener() { public void connected(final Connection connection) { serverObjectSpace.addConnection(connection); runTest(connection, 12, 1234); } public void received(Connection connection, Object object) { if (!(object instanceof MessageWithTestObject)) return; MessageWithTestObject m = (MessageWithTestObject) object; System.out.println(serverTestObject.value); System.out.println(((TestObjectImpl) m.testObject).value); assertEquals(4321f, m.testObject.other()); stopEndPoints(2000); } }); // ---- Client client = new Client(); register(client.getKryo()); ObjectSpace clientObjectSpace = new ObjectSpace(client); final TestObjectImpl clientTestObject = new TestObjectImpl(1234); clientObjectSpace.register((short) 12, clientTestObject); startEndPoint(client); client.addListener( new Listener() { public void connected(final Connection connection) { RmiTest.runTest(connection, 42, 4321); } public void received(Connection connection, Object object) { if (!(object instanceof MessageWithTestObject)) return; MessageWithTestObject m = (MessageWithTestObject) object; System.out.println(clientTestObject.value); System.out.println(((TestObjectImpl) m.testObject).value); assertEquals(1234f, m.testObject.other()); stopEndPoints(2000); } }); client.connect(5000, host, tcpPort); waitForThreads(); }
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()); }