Search in sources :

Example 1 with PacketDecoder

use of de.datasecs.hydra.shared.protocol.packets.serialization.PacketDecoder in project Hydra by DataSecs.

the class HydraChannelInitializer method initChannel.

@Override
protected void initChannel(SocketChannel channel) {
    ChannelPipeline pipeline = channel.pipeline();
    // In
    pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
    pipeline.addLast(new PacketDecoder(protocol));
    // Out
    pipeline.addLast(new LengthFieldPrepender(4));
    pipeline.addLast(new PacketEncoder(protocol));
    HydraSession session = new HydraSession(channel, protocol);
    pipeline.addLast(session);
    // Add sessions to protocol, to keep track of them
    if (isServer) {
        protocol.addSession(session);
    } else {
        protocol.setClientSession(session);
    }
    // Inform SessionListener about new session
    protocol.callSessionListener(true, session);
}
Also used : PacketEncoder(de.datasecs.hydra.shared.protocol.packets.serialization.PacketEncoder) HydraSession(de.datasecs.hydra.shared.handler.HydraSession) PacketDecoder(de.datasecs.hydra.shared.protocol.packets.serialization.PacketDecoder) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 2 with PacketDecoder

use of de.datasecs.hydra.shared.protocol.packets.serialization.PacketDecoder in project Hydra by DataSecs.

the class HydraChannelInitializer method initChannel.

@Override
protected void initChannel(C channel) {
    ChannelPipeline pipeline = channel.pipeline();
    // In
    pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
    pipeline.addLast(new PacketDecoder(protocol));
    // Out
    pipeline.addLast(new LengthFieldPrepender(4));
    pipeline.addLast(new PacketEncoder(protocol));
    /*
        if (!useUDP) {
            TCPHydraSession session = new TCPHydraSession(channel, protocol);
            pipeline.addLast(session);
        } else {
            UDPHydraSession session = new UDPHydraSession(channel, protocol);
            pipeline.addLast(session);
        }
         */
    HydraSession session = new HydraSession(channel, protocol);
    pipeline.addLast(session);
    // Add sessions to protocol, to keep track of them
    if (isServer) {
        protocol.addSession(session);
    } else {
        protocol.setClientSession(session);
    }
    if (!useUDP) {
        if (protocol.getSessionListener() != null) {
            // Inform SessionListener about new session
            protocol.callSessionListener(true, session);
        } else if (protocol.getSessionConsumer() != null) {
            // Inform SessionConsumer about new session
            protocol.callSessionConsumer(true, session);
        }
    }
}
Also used : PacketEncoder(de.datasecs.hydra.shared.protocol.packets.serialization.PacketEncoder) TCPHydraSession(de.datasecs.hydra.shared.handler.impl.TCPHydraSession) HydraSession(de.datasecs.hydra.shared.handler.impl.HydraSession) UDPHydraSession(de.datasecs.hydra.shared.handler.impl.UDPHydraSession) PacketDecoder(de.datasecs.hydra.shared.protocol.packets.serialization.PacketDecoder) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

PacketDecoder (de.datasecs.hydra.shared.protocol.packets.serialization.PacketDecoder)2 PacketEncoder (de.datasecs.hydra.shared.protocol.packets.serialization.PacketEncoder)2 ChannelPipeline (io.netty.channel.ChannelPipeline)2 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)2 LengthFieldPrepender (io.netty.handler.codec.LengthFieldPrepender)2 HydraSession (de.datasecs.hydra.shared.handler.HydraSession)1 HydraSession (de.datasecs.hydra.shared.handler.impl.HydraSession)1 TCPHydraSession (de.datasecs.hydra.shared.handler.impl.TCPHydraSession)1 UDPHydraSession (de.datasecs.hydra.shared.handler.impl.UDPHydraSession)1