Search in sources :

Example 1 with TestServerProtocol

use of de.datasecs.hydra.server.TestServerProtocol in project Hydra by DataSecs.

the class HydraTest method init.

public static void init() {
    server = new Server.Builder("localhost", 8888, new TestServerProtocol()).addListener(new HydraSessionListener() {

        @Override
        public void onConnected(Session session) {
            System.out.println("TestClient connected!");
            synchronized (LOCK) {
                clientConnected = true;
                LOCK.notify();
            }
        }

        @Override
        public void onDisconnected(Session session) {
            System.out.println("TestClient disconnected!");
        }
    }).option(ChannelOption.SO_BACKLOG, 200).childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_KEEPALIVE, true).build();
    System.out.println("Server started successfully!");
    client = new Client.Builder("localhost", 8888, new TestClientProtocol()).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();
    System.out.println("Client started successfully!");
}
Also used : TestServerProtocol(de.datasecs.hydra.server.TestServerProtocol) TestClientProtocol(de.datasecs.hydra.client.TestClientProtocol) HydraSessionListener(de.datasecs.hydra.shared.handler.listener.HydraSessionListener) Session(de.datasecs.hydra.shared.handler.Session)

Aggregations

TestClientProtocol (de.datasecs.hydra.client.TestClientProtocol)1 TestServerProtocol (de.datasecs.hydra.server.TestServerProtocol)1 Session (de.datasecs.hydra.shared.handler.Session)1 HydraSessionListener (de.datasecs.hydra.shared.handler.listener.HydraSessionListener)1