Search in sources :

Example 1 with SampleProtocol

use of server.SampleProtocol in project Hydra by DataSecs.

the class ExampleSerializationServer method main.

public static void main(String[] args) {
    HydraServer server = new Server.Builder("localhost", 8888, new SampleProtocol()).bossThreads(2).workerThreads(4).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_KEEPALIVE, true).childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_KEEPALIVE, true).addListener(new HydraSessionListener() {

        @Override
        public void onConnected(Session session) {
            System.out.println("\nClient connected!");
        }

        @Override
        public void onDisconnected(Session session) {
            System.out.println("\nClient disconnected!");
        }
    }).build();
    if (server.isActive()) {
        System.out.println("Server is online!");
        // Returns the local address of the server that was set in the constructor
        System.out.printf("Socket address: %s%n", server.getLocalAdress());
    }
}
Also used : HydraServer(de.datasecs.hydra.server.HydraServer) HydraSessionListener(de.datasecs.hydra.shared.handler.listener.HydraSessionListener) SampleProtocol(server.SampleProtocol) Session(de.datasecs.hydra.shared.handler.Session)

Aggregations

HydraServer (de.datasecs.hydra.server.HydraServer)1 Session (de.datasecs.hydra.shared.handler.Session)1 HydraSessionListener (de.datasecs.hydra.shared.handler.listener.HydraSessionListener)1 SampleProtocol (server.SampleProtocol)1