List of usage examples for io.netty.channel ChannelOption SO_REUSEADDR
ChannelOption SO_REUSEADDR
To view the source code for io.netty.channel ChannelOption SO_REUSEADDR.
Click Source Link
From source file:org.iotivity.cloud.base.connector.CoapConnector.java
License:Open Source License
public CoapConnector() { mBootstrap.group(mConnectorGroup);/* w ww .j a v a 2 s. c o m*/ mBootstrap.channel(NioSocketChannel.class); mBootstrap.option(ChannelOption.TCP_NODELAY, true); mBootstrap.option(ChannelOption.SO_KEEPALIVE, true); mBootstrap.option(ChannelOption.SO_REUSEADDR, true); }
From source file:org.jmqtt.broker.acceptor.NettyAcceptor.java
License:Open Source License
private void initFactory(String host, int port, final PipelineInitializer pipeliner) { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override/*from www .j av a 2s .c om*/ public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); try { pipeliner.init(pipeline); } catch (Throwable th) { LOG.error("Severe error during pipeline creation", th); throw th; } } }).option(ChannelOption.SO_BACKLOG, 128).option(ChannelOption.SO_REUSEADDR, true) .option(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_KEEPALIVE, true); try { // Bind and start to accept incoming connections. ChannelFuture f = b.bind(host, port); LOG.info("Server binded host: {}, port: {}", host, port); f.sync(); } catch (InterruptedException ex) { LOG.error(null, ex); } }
From source file:org.jpos.qrest.RestServer.java
License:Open Source License
@Override protected void initService() throws GeneralSecurityException, IOException { sp = SpaceFactory.getSpace();//from ww w.java 2 s. com final SSLContext sslContext = enableTLS ? getSSLContext() : null; bossGroup = new NioEventLoopGroup(); workerGroup = new NioEventLoopGroup(); serverBootstrap = new ServerBootstrap(); serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { int timeout = cfg.getInt("timeout", 300); ch.pipeline().addLast(new IdleStateHandler(timeout, timeout, timeout)); if (enableTLS) { ch.pipeline().addLast(new SslHandler(getSSLEngine(sslContext), true)); } ch.pipeline().addLast(new HttpServerCodec()); ch.pipeline().addLast(new HttpObjectAggregator(512 * 1024)); ch.pipeline().addLast(new RestSession(RestServer.this)); } }).option(ChannelOption.SO_BACKLOG, 128).option(ChannelOption.SO_REUSEADDR, true) .childOption(ChannelOption.SO_KEEPALIVE, true); if (enableTLS) { logSSLEngineInfo(getSSLEngine(sslContext)); } }
From source file:org.jupiter.transport.netty.NettyTcpAcceptor.java
License:Apache License
@Override protected void setOptions() { super.setOptions(); ServerBootstrap boot = bootstrap();/*from ww w.j a v a 2 s . com*/ // parent options NettyConfig.NettyTcpConfigGroup.ParentConfig parent = configGroup.parent(); boot.option(ChannelOption.SO_BACKLOG, parent.getBacklog()); boot.option(ChannelOption.SO_REUSEADDR, parent.isReuseAddress()); if (parent.getRcvBuf() > 0) { boot.option(ChannelOption.SO_RCVBUF, parent.getRcvBuf()); } // child options NettyConfig.NettyTcpConfigGroup.ChildConfig child = configGroup.child(); boot.childOption(ChannelOption.SO_REUSEADDR, child.isReuseAddress()) .childOption(ChannelOption.SO_KEEPALIVE, child.isKeepAlive()) .childOption(ChannelOption.TCP_NODELAY, child.isTcpNoDelay()) .childOption(ChannelOption.ALLOW_HALF_CLOSURE, child.isAllowHalfClosure()); if (child.getRcvBuf() > 0) { boot.childOption(ChannelOption.SO_RCVBUF, child.getRcvBuf()); } if (child.getSndBuf() > 0) { boot.childOption(ChannelOption.SO_SNDBUF, child.getSndBuf()); } if (child.getLinger() > 0) { boot.childOption(ChannelOption.SO_LINGER, child.getLinger()); } if (child.getIpTos() > 0) { boot.childOption(ChannelOption.IP_TOS, child.getIpTos()); } int bufLowWaterMark = child.getWriteBufferLowWaterMark(); int bufHighWaterMark = child.getWriteBufferHighWaterMark(); if (bufLowWaterMark >= 0 && bufHighWaterMark > 0) { WriteBufferWaterMark waterMark = new WriteBufferWaterMark(bufLowWaterMark, bufHighWaterMark); boot.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, waterMark); } }
From source file:org.jupiter.transport.netty.NettyTcpConnector.java
License:Apache License
@Override protected void setOptions() { super.setOptions(); Bootstrap boot = bootstrap();/* w w w . j a v a 2s . com*/ NettyConfig.NettyTcpConfigGroup.ChildConfig child = childConfig; // child options boot.option(ChannelOption.SO_REUSEADDR, child.isReuseAddress()) .option(ChannelOption.SO_KEEPALIVE, child.isKeepAlive()) .option(ChannelOption.TCP_NODELAY, child.isTcpNoDelay()) .option(ChannelOption.ALLOW_HALF_CLOSURE, child.isAllowHalfClosure()); if (child.getRcvBuf() > 0) { boot.option(ChannelOption.SO_RCVBUF, child.getRcvBuf()); } if (child.getSndBuf() > 0) { boot.option(ChannelOption.SO_SNDBUF, child.getSndBuf()); } if (child.getLinger() > 0) { boot.option(ChannelOption.SO_LINGER, child.getLinger()); } if (child.getIpTos() > 0) { boot.option(ChannelOption.IP_TOS, child.getIpTos()); } if (child.getConnectTimeoutMillis() > 0) { boot.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, child.getConnectTimeoutMillis()); } int bufLowWaterMark = child.getWriteBufferLowWaterMark(); int bufHighWaterMark = child.getWriteBufferHighWaterMark(); if (bufLowWaterMark >= 0 && bufHighWaterMark > 0) { WriteBufferWaterMark waterMark = new WriteBufferWaterMark(bufLowWaterMark, bufHighWaterMark); boot.option(ChannelOption.WRITE_BUFFER_WATER_MARK, waterMark); } }
From source file:org.jupiter.transport.netty.NettyUdtAcceptor.java
License:Apache License
@Override protected void setOptions() { super.setOptions(); ServerBootstrap boot = bootstrap();/*from w ww.ja v a 2 s . c om*/ // parent options NettyUdtConfigGroup.ParentConfig parent = configGroup.parent(); boot.option(ChannelOption.SO_BACKLOG, parent.getBacklog()); // child options NettyUdtConfigGroup.ChildConfig child = configGroup.child(); boot.childOption(ChannelOption.SO_REUSEADDR, child.isReuseAddress()); if (child.getRcvBuf() > 0) { boot.childOption(ChannelOption.SO_RCVBUF, child.getRcvBuf()); } if (child.getSndBuf() > 0) { boot.childOption(ChannelOption.SO_SNDBUF, child.getSndBuf()); } if (child.getLinger() > 0) { boot.childOption(ChannelOption.SO_LINGER, child.getLinger()); } int bufLowWaterMark = child.getWriteBufferLowWaterMark(); int bufHighWaterMark = child.getWriteBufferHighWaterMark(); if (bufLowWaterMark >= 0 && bufHighWaterMark > 0) { WriteBufferWaterMark waterMark = new WriteBufferWaterMark(bufLowWaterMark, bufHighWaterMark); boot.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, waterMark); } }
From source file:org.jupiter.transport.netty.NettyUdtConnector.java
License:Apache License
@Override protected void setOptions() { super.setOptions(); Bootstrap boot = bootstrap();/*from w w w .j av a 2 s . c o m*/ NettyUdtConfigGroup.ChildConfig child = childConfig; // child options boot.option(ChannelOption.SO_REUSEADDR, child.isReuseAddress()); if (child.getRcvBuf() > 0) { boot.option(ChannelOption.SO_RCVBUF, child.getRcvBuf()); } if (child.getSndBuf() > 0) { boot.option(ChannelOption.SO_SNDBUF, child.getSndBuf()); } if (child.getLinger() > 0) { boot.option(ChannelOption.SO_LINGER, child.getLinger()); } if (child.getConnectTimeoutMillis() > 0) { boot.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, child.getConnectTimeoutMillis()); } int bufLowWaterMark = child.getWriteBufferLowWaterMark(); int bufHighWaterMark = child.getWriteBufferHighWaterMark(); if (bufLowWaterMark >= 0 && bufHighWaterMark > 0) { WriteBufferWaterMark waterMark = new WriteBufferWaterMark(bufLowWaterMark, bufHighWaterMark); boot.option(ChannelOption.WRITE_BUFFER_WATER_MARK, waterMark); } }
From source file:org.kaaproject.kaa.server.common.server.AbstractNettyServer.java
License:Apache License
/** * Netty HTTP server initialization.//from w ww.j a va 2 s . c o m */ public void init() { try { LOG.info("NettyServer Initializing..."); bossGroup = new NioEventLoopGroup(); LOG.debug("NettyServer bossGroup created"); workerGroup = new NioEventLoopGroup(); LOG.debug("NettyServer workGroup created"); btsServer = new ServerBootstrap(); LOG.debug("NettyServer ServerBootstrap created"); ChannelInitializer<SocketChannel> serverInit = configureInitializer(); LOG.debug("NettyServer InitClass instance created"); LOG.debug("NettyServer InitClass instance init()"); btsServer.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(serverInit) .option(ChannelOption.SO_REUSEADDR, true); LOG.debug("NettyServer ServerBootstrap group initialized"); bindChannel = btsServer.bind(bindAddress, bindPort).sync().channel(); } catch (Exception exception) { LOG.error("NettyHttpServer init() failed", exception); } }
From source file:org.msgpack.rpc.loop.netty.NettyTcpServerTransport.java
License:Apache License
NettyTcpServerTransport(TcpServerConfig config, Server server, NettyEventLoop loop, Class<? extends RpcMessageHandler> rpcHandlerClass) { if (server == null) { throw new IllegalArgumentException("Server must not be null"); }/*ww w . j a va 2s.c o m*/ Address address = config.getListenAddress(); try { RpcMessageHandler handler = rpcHandlerClass.getConstructor(Server.class).newInstance(server); handler.useThread(true); ServerBootstrap bootstrap = new ServerBootstrap().group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class); bootstrap.childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast("msgpack-decode-stream", new MessagePackStreamDecoder(loop.getMessagePack())); p.addLast("msgpack-encode", new MessagePackEncoder(loop.getMessagePack())); p.addLast("message", new MessageHandler(handler)); } }); bootstrap.childOption(ChannelOption.TCP_NODELAY, true); bootstrap.option(ChannelOption.SO_REUSEADDR, true); bootstrap.option(ChannelOption.TCP_NODELAY, true); bootstrap.localAddress(address.getSocketAddress()); future = bootstrap.bind(); } catch (Exception e) { throw new RuntimeException(e); } // RpcMessageHandler handler = new RpcMessageHandlerEx(server); }
From source file:org.onosproject.artemis.impl.moas.MoasServerController.java
License:Apache License
/** * Create netty server bootstrap./* ww w . j av a2s . c o m*/ * * @return bootstrap */ private ServerBootstrap createServerBootStrap() { bossGroup = new NioEventLoopGroup(); workerGroup = new NioEventLoopGroup(); return new ServerBootstrap().group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_REUSEADDR, true).childOption(ChannelOption.SO_KEEPALIVE, true) .childOption(ChannelOption.TCP_NODELAY, true); }