Search in sources :

Example 1 with GeneratedProtocolMessageCodec

use of org.apache.plc4x.java.spi.connection.GeneratedProtocolMessageCodec in project plc4x by apache.

the class S7ServerModule method start.

@Override
public void start() throws SimulatorExcepiton {
    if (loopGroup != null) {
        return;
    }
    try {
        loopGroup = new NioEventLoopGroup();
        workerGroup = new NioEventLoopGroup();
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(loopGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {

            @Override
            public void initChannel(SocketChannel channel) {
                ChannelPipeline pipeline = channel.pipeline();
                pipeline.addLast(new GeneratedProtocolMessageCodec<>(TPKTPacket.class, TPKTPacket::staticParse, ByteOrder.BIG_ENDIAN, null, new S7Driver.ByteLengthEstimator(), new S7Driver.CorruptPackageCleaner()));
                pipeline.addLast(new S7Step7ServerAdapter(context));
            }
        }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);
        bootstrap.bind(ISO_ON_TCP_PORT).sync();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new SimulatorExcepiton(e);
    }
}
Also used : NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) GeneratedProtocolMessageCodec(org.apache.plc4x.java.spi.connection.GeneratedProtocolMessageCodec) TPKTPacket(org.apache.plc4x.java.s7.readwrite.TPKTPacket) SimulatorExcepiton(org.apache.plc4x.simulator.exceptions.SimulatorExcepiton) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline) S7Step7ServerAdapter(org.apache.plc4x.simulator.server.s7.protocol.S7Step7ServerAdapter) S7Driver(org.apache.plc4x.java.s7.readwrite.S7Driver) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 2 with GeneratedProtocolMessageCodec

use of org.apache.plc4x.java.spi.connection.GeneratedProtocolMessageCodec in project plc4x by apache.

the class Plc4xServer method start.

public void start() throws PlcException {
    if (loopGroup != null) {
        return;
    }
    try {
        loopGroup = new NioEventLoopGroup();
        workerGroup = new NioEventLoopGroup();
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(loopGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {

            @Override
            public void initChannel(SocketChannel channel) {
                ChannelPipeline pipeline = channel.pipeline();
                pipeline.addLast(new GeneratedProtocolMessageCodec<>(Plc4xMessage.class, Plc4xMessage::staticParse, ByteOrder.BIG_ENDIAN, null, new ByteLengthEstimator(), null));
                pipeline.addLast(new Plc4xServerAdapter());
            }
        }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);
        bootstrap.bind(Plc4xConstants.PLC4XTCPDEFAULTPORT).sync();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new PlcException(e);
    }
}
Also used : NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) Plc4xMessage(org.apache.plc4x.java.plc4x.readwrite.Plc4xMessage) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) GeneratedProtocolMessageCodec(org.apache.plc4x.java.spi.connection.GeneratedProtocolMessageCodec) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline) PlcException(org.apache.plc4x.java.api.exceptions.PlcException) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Plc4xServerAdapter(org.apache.plc4x.java.tools.plc4xserver.protocol.Plc4xServerAdapter)

Aggregations

ServerBootstrap (io.netty.bootstrap.ServerBootstrap)2 ChannelPipeline (io.netty.channel.ChannelPipeline)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 SocketChannel (io.netty.channel.socket.SocketChannel)2 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)2 GeneratedProtocolMessageCodec (org.apache.plc4x.java.spi.connection.GeneratedProtocolMessageCodec)2 PlcException (org.apache.plc4x.java.api.exceptions.PlcException)1 Plc4xMessage (org.apache.plc4x.java.plc4x.readwrite.Plc4xMessage)1 S7Driver (org.apache.plc4x.java.s7.readwrite.S7Driver)1 TPKTPacket (org.apache.plc4x.java.s7.readwrite.TPKTPacket)1 Plc4xServerAdapter (org.apache.plc4x.java.tools.plc4xserver.protocol.Plc4xServerAdapter)1 SimulatorExcepiton (org.apache.plc4x.simulator.exceptions.SimulatorExcepiton)1 S7Step7ServerAdapter (org.apache.plc4x.simulator.server.s7.protocol.S7Step7ServerAdapter)1