Search in sources :

Example 1 with S7Step7ServerAdapter

use of org.apache.plc4x.simulator.server.s7.protocol.S7Step7ServerAdapter 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)

Aggregations

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