Search in sources :

Example 1 with SampleSerializationPacket

use of client.packets.SampleSerializationPacket in project Hydra by DataSecs.

the class ExampleSerializationClient method main.

public static void main(String[] args) {
    HydraClient client = new Client.Builder("localhost", 8888, new SampleProtocol()).workerThreads(4).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_KEEPALIVE, true).addSessionListener(new HydraSessionListener() {

        @Override
        public void onConnected(Session session) {
            System.out.println("Connected to server!");
        }

        @Override
        public void onDisconnected(Session session) {
            System.out.println("\nDisconnected from server!");
        }
    }).build();
    if (client.isConnected()) {
        session = client.getSession();
        System.out.println("\nClient is online!");
        System.out.printf("Socket address: %s%n", session.getAddress());
    }
    // Create custom classes and necessary stuff for example serialization
    List<String> testStringList = new ArrayList<>();
    testStringList.add("Hydra");
    testStringList.add("Serialization");
    testStringList.add("Test");
    CustomClassExtended customClassExtended = new CustomClassExtended("testStringExtended", UUID.randomUUID(), 5L, Integer.class);
    CustomClass customClass = new CustomClass("testString", 1, new String[] { "Hydra", "serialization" }, testStringList, "this is a random object", customClassExtended);
    // Sends the instance of a custom class, that is create and filled with data above
    session.send(new SampleSerializationPacket(customClass));
}
Also used : HydraClient(de.datasecs.hydra.client.HydraClient) SampleSerializationPacket(client.packets.SampleSerializationPacket) ArrayList(java.util.ArrayList) HydraClient(de.datasecs.hydra.client.HydraClient) Client(de.datasecs.hydra.client.Client) HydraSessionListener(de.datasecs.hydra.shared.handler.listener.HydraSessionListener) SampleProtocol(client.SampleProtocol) Session(de.datasecs.hydra.shared.handler.Session)

Aggregations

SampleProtocol (client.SampleProtocol)1 SampleSerializationPacket (client.packets.SampleSerializationPacket)1 Client (de.datasecs.hydra.client.Client)1 HydraClient (de.datasecs.hydra.client.HydraClient)1 Session (de.datasecs.hydra.shared.handler.Session)1 HydraSessionListener (de.datasecs.hydra.shared.handler.listener.HydraSessionListener)1 ArrayList (java.util.ArrayList)1