Example usage for io.netty.channel ChannelOption SO_TIMEOUT

List of usage examples for io.netty.channel ChannelOption SO_TIMEOUT

Introduction

In this page you can find the example usage for io.netty.channel ChannelOption SO_TIMEOUT.

Prototype

ChannelOption SO_TIMEOUT

To view the source code for io.netty.channel ChannelOption SO_TIMEOUT.

Click Source Link

Usage

From source file:jj.http.server.HttpServer.java

License:Apache License

private void makeServerBootstrap(int bindingCount) {
    serverBootstrap = new ServerBootstrap()
            .group(new NioEventLoopGroup(bindingCount, threadFactory), ioEventLoopGroup)
            .channel(NioServerSocketChannel.class).childHandler(initializer)
            .option(ChannelOption.SO_KEEPALIVE, configuration.keepAlive())
            .option(ChannelOption.SO_REUSEADDR, configuration.reuseAddress())
            .option(ChannelOption.TCP_NODELAY, configuration.tcpNoDelay())
            .option(ChannelOption.SO_TIMEOUT, configuration.timeout())
            .option(ChannelOption.SO_BACKLOG, configuration.backlog())
            .option(ChannelOption.SO_RCVBUF, configuration.receiveBufferSize())
            .option(ChannelOption.SO_SNDBUF, configuration.sendBufferSize());
}

From source file:net.epsilony.utils.codec.modbus.ModbusClientMaster.java

License:Open Source License

protected ChannelFuture genConnectFuture() {

    initializer = new SimpModbusMasterChannelInitializer();
    initializer.setRequestLifeTime(requestLifeTime);
    bootstrap = new Bootstrap();
    bootstrap.group(group).channelFactory(channelFactory).handler(initializer)
            .option(ChannelOption.TCP_NODELAY, tcpNoDelay).option(ChannelOption.SO_KEEPALIVE, keepAlive)
            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeout)
            .option(ChannelOption.SO_TIMEOUT, socketTimeout);
    return bootstrap.connect(innetAddress, inetPort);
}

From source file:org.ddpush.im.v1.node.pushlistener.NettyPushListener.java

License:Apache License

public void initChannel() throws Exception {
    bossGroup = new EpollEventLoopGroup();
    workerGroup = new EpollEventLoopGroup(pushListenerWorkerNum,
            new ThreadFactoryWithName(NettyPushListener.class));
    serverBootstarp = new ServerBootstrap().group(bossGroup, workerGroup)
            .channel(EpollServerSocketChannel.class).option(ChannelOption.SO_TIMEOUT, sockTimout)
            .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
            .option(ChannelOption.TCP_NODELAY, true)
            .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
            .childOption(ChannelOption.TCP_NODELAY, true).childHandler(pushListenerChannelInitializer);

    serverBootstarp.bind(port).sync();/*from  ww w . j av a 2 s.  c om*/

    logger.info("Netty TCP Push Listener nio provider: {} with {} workers",
            serverBootstarp.getClass().getCanonicalName(), pushListenerWorkerNum);
}

From source file:org.gamejam.gc.fartroulette.WhoFartedServer.java

License:Apache License

public void run() throws Exception {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {/* w  w  w.  j  a  v  a2  s.  co m*/
        final ServerBootstrap sb = new ServerBootstrap();
        sb.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(final SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new HttpRequestDecoder(), new HttpObjectAggregator(65536),
                                new HttpResponseEncoder(),
                                new HttpStaticFileServerHandler(true, "websocket", "api"),
                                new WebSocketServerProtocolHandler("/websocket"),
                                new WebSocketFrameHandler(s_allChannels, s_elevatorData));

                    }
                }).option(ChannelOption.SO_BACKLOG, 128).option(ChannelOption.SO_TIMEOUT, 100)
                .childOption(ChannelOption.SO_KEEPALIVE, true);

        //loadDummyData();

        runUpdaterThread();

        runGame();

        final Channel ch = sb.bind(port).sync().channel();
        System.out.println("Web socket server started at port " + port);

        ch.closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:org.lightmare.remote.rpc.RPCall.java

License:Open Source License

/**
 * Prepares {@link Bootstrap} for RPC service client connection
 * // w  ww  .j  ava  2  s . c om
 * @return {@link Bootstrap}
 */
private Bootstrap getBootstrap() {

    Bootstrap bootstrap = new Bootstrap();

    bootstrap.group(worker);
    bootstrap.channel(NioSocketChannel.class);
    bootstrap.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE);

    if (timeout > ZERO_TIMEOUT) {
        bootstrap.option(ChannelOption.SO_TIMEOUT, timeout);
    }

    handler = new RcpHandler();
    bootstrap.handler(new ChannelInitializerImpl(handler));

    return bootstrap;
}

From source file:org.lightmare.remote.rpc.RpcListener.java

License:Open Source License

/**
 * Starts RPC server//from www .j  a  va  2 s  . c  o  m
 * 
 */
public static void startServer(Configuration config) {

    setNettyPools(config);

    try {
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(boss, worker).channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializerImpl());

        bootstrap.option(ChannelOption.SO_BACKLOG, 500);
        bootstrap.childOption(ChannelOption.SO_KEEPALIVE, Boolean.TRUE);
        bootstrap.childOption(ChannelOption.SO_TIMEOUT, config.getIntValue(ConfigKeys.CONNECTION_TIMEOUT.key));

        InetSocketAddress address = new InetSocketAddress(
                Inet4Address.getByName(config.getStringValue("listening_ip")),
                config.getIntValue("listening_port"));
        ChannelFuture future = bootstrap.bind(address).sync();
        LOG.info(future);
    } catch (UnknownHostException ex) {
        LOG.error(ex.getMessage(), ex);
    } catch (InterruptedException ex) {
        LOG.error(ex.getMessage(), ex);
    }
}

From source file:pl.tcs.btppllib.DeviceGetTimeTest.java

public static void main(String[] args) throws Exception {
    final String connectionStr = args[0];
    String[] connParams = connectionStr.split(":");

    String host = connParams[0];/*from   w  ww.j  av a2s .c  o m*/
    int port = Integer.parseInt(connParams[1]);
    log.info(String.format("***** Running test on host=%s and port=%d", host, port));

    EventLoopGroup workerGroup = new NioEventLoopGroup();

    try {
        Bootstrap b = new Bootstrap(); // (1)
        b.group(workerGroup); // (2)
        b.channel(NioSocketChannel.class); // (3)
        b.option(ChannelOption.SO_KEEPALIVE, true); // (4)
        b.option(ChannelOption.SO_TIMEOUT, 10000);
        //            b.option(ChannelOption.SO_REUSEADDR, true);
        b.handler(new ChannelInitializer<SocketChannel>() {
            @Override
            protected void initChannel(SocketChannel c) throws Exception {
                ChannelPipeline pipeline = c.pipeline();
                pipeline.addLast("frameJoiner", new OcitMessageDecoder());
                pipeline.addLast("frameDecoder",
                        new LengthFieldBasedFrameDecoder(MAX_FRAME_LENGTH, 3, 1, 0, 4));
                //                    pipeline.addLast("frameJoiner", new OcitMessageDecoder());
                pipeline.addLast("timeHandler", new GetTimeTestHandler());
            }
        });

        ChannelFuture f = b.connect(host, port).sync(); // (5)

        Channel c = f.channel();
        c.writeAndFlush(buildGetTimeRequest()).addListener(new ChannelFutureListener() {

            @Override
            public void operationComplete(ChannelFuture f) throws Exception {
                if (f.isSuccess()) {
                    log.info("*** GetTime request sent with success!!!");
                } else {
                    log.error("*** ERROR when sending GetTime request");
                }
            }
        });

        //            c.closeFuture().sync();        

    } finally {
        //            workerGroup.shutdownGracefully();
    }
}

From source file:pl.tcs.btppllib.OcitClient.java

public Channel bootstrapClient(String host, int port) {
    log.info(String.format("Bootstrapping client on host=%s and port=%d", host, port));

    EventLoopGroup workerGroup = new NioEventLoopGroup();
    eventLoopGroups.add(workerGroup);/*from   w ww  .  j a v  a  2 s .c  om*/

    try {
        Bootstrap b = new Bootstrap();
        b.group(workerGroup);
        b.channel(NioSocketChannel.class);
        b.option(ChannelOption.SO_KEEPALIVE, true);
        b.option(ChannelOption.SO_TIMEOUT, 100 * 1000);
        //            b.option(ChannelOption.SO_REUSEADDR, true);
        b.handler(new ChannelInitializer<SocketChannel>() {
            @Override
            protected void initChannel(SocketChannel c) throws Exception {
                ChannelPipeline pipeline = c.pipeline();

                // assemble + header analyzing
                pipeline.addLast("frameAssembler", CustomHandlers.getPacketAssemblerDecoder());
                pipeline.addLast("frameLengthFieldShortenDecoder",
                        CustomHandlers.getLengthFieldShortenDecoder());

                // custom frame handling, packet mutex!
                pipeline.addLast("frameHandler", new OcitResponseTelegramHandler());
            }
        });

        ChannelFuture f = b.connect(host, port).sync();

        log.info("Done!!!!!!!!!!!!!");

        return f.channel();
    } catch (InterruptedException e) {
        log.error(e.getMessage());
        throw new CriticalException(e);
    }
}