Search in sources :

Example 1 with ExampleSerializationPacket

use of de.datasecs.hydra.example.shared.serialization.ExampleSerializationPacket in project Hydra by DataSecs.

the class ExampleSerializationClient method main.

public static void main(String[] args) {
    HydraClient client = new Client.Builder("localhost", 8888, new ExampleSerializationClientProtocol()).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 ExampleSerializationPacket(customClass));
}
Also used : HydraClient(de.datasecs.hydra.client.HydraClient) ExampleSerializationPacket(de.datasecs.hydra.example.shared.serialization.ExampleSerializationPacket) ArrayList(java.util.ArrayList) HydraClient(de.datasecs.hydra.client.HydraClient) Client(de.datasecs.hydra.client.Client) HydraSessionListener(de.datasecs.hydra.shared.handler.listener.HydraSessionListener) CustomClassExtended(de.datasecs.hydra.example.shared.serialization.CustomClassExtended) Session(de.datasecs.hydra.shared.handler.Session) CustomClass(de.datasecs.hydra.example.shared.serialization.CustomClass)

Aggregations

Client (de.datasecs.hydra.client.Client)1 HydraClient (de.datasecs.hydra.client.HydraClient)1 CustomClass (de.datasecs.hydra.example.shared.serialization.CustomClass)1 CustomClassExtended (de.datasecs.hydra.example.shared.serialization.CustomClassExtended)1 ExampleSerializationPacket (de.datasecs.hydra.example.shared.serialization.ExampleSerializationPacket)1 Session (de.datasecs.hydra.shared.handler.Session)1 HydraSessionListener (de.datasecs.hydra.shared.handler.listener.HydraSessionListener)1 ArrayList (java.util.ArrayList)1