List of usage examples for io.netty.channel ChannelOption TCP_NODELAY
ChannelOption TCP_NODELAY
To view the source code for io.netty.channel ChannelOption TCP_NODELAY.
Click Source Link
From source file:org.shelloid.vpt.agent.LocalLink.java
License:Open Source License
public Bootstrap getClientBootstrap() throws InterruptedException { EventLoopGroup group = new NioEventLoopGroup(); Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true) .handler(new ChannelInitializer<SocketChannel>() { @Override//from w ww .jav a2 s.c o m public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(new SvcSideAgentHandler()); } }); return b; }
From source file:org.spout.engine.SpoutServer.java
License:Open Source License
@Override public void init(SpoutApplication args) { super.init(args); bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new CommonChannelInitializer()).childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.SO_KEEPALIVE, true); accessManager.load();//from w ww. ja v a2 s . c om accessManager.setWhitelistEnabled(SpoutConfiguration.WHITELIST_ENABLED.getBoolean()); }
From source file:org.springframework.boot.context.embedded.netty.NettyEmbeddedServletContainer.java
License:Apache License
private void groups(ServerBootstrap b) { //comment the epoll codes, the epoll evn is hard to build /* if (StandardSystemProperty.OS_NAME.value().equals("Linux")) { bossGroup = new EpollEventLoopGroup(1); workerGroup = new EpollEventLoopGroup(); b.channel(EpollServerSocketChannel.class) .group(bossGroup, workerGroup) .option(EpollChannelOption.TCP_CORK, true); } else {/*from w ww . jav a 2 s . c om*/ bossGroup = new NioEventLoopGroup(1); workerGroup = new NioEventLoopGroup(); b.channel(NioServerSocketChannel.class) .group(bossGroup, workerGroup); }*/ bossGroup = new NioEventLoopGroup(1); workerGroup = new NioEventLoopGroup(); b.channel(NioServerSocketChannel.class).group(bossGroup, workerGroup); b.option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_REUSEADDR, true) .option(ChannelOption.SO_BACKLOG, 100); logger.info("Bootstrap configuration: " + b.toString()); }
From source file:org.starnub.starnubserver.servers.starbound.TCPProxyServer.java
License:Open Source License
public void start() { ServerBootstrap starNubInbound_TCP_Socket = new ServerBootstrap(); serverChannel = starNubInbound_TCP_Socket.group(connectionBossGroup, connectionWorkerGroup) .channel(channelClass).option(ChannelOption.SO_BACKLOG, serverBacklog) .childOption(ChannelOption.TCP_NODELAY, noDelay).childOption(ChannelOption.ALLOCATOR, socketBuffer) .childHandler(new TCPProxyServerInitializer(starboundAddress, starboundPort)).bind(starnubPort) .channel();//from w w w . j a v a2s . c o m }
From source file:org.starnub.starnubserver.servers.starbound.TCPProxyServerPacketDecoder.java
License:Open Source License
private boolean openServerConnection(ChannelHandlerContext ctx) { new StarNubEvent("StarNub_Socket_Connection_Attempt_Server", ctx); Bootstrap starNubMainOutboundSocket = new Bootstrap(); starNubMainOutboundSocket.group(ctx.channel().eventLoop()).channel(ctx.channel().getClass()) .option(ChannelOption.TCP_NODELAY, StarboundServer.getInstance().getTcpProxyServer().isNoDelay()) .option(ChannelOption.ALLOCATOR, StarboundServer.getInstance().getTcpProxyServer().getSocketBuffer()) .handler(new TCPProxyServerPacketDecoder(Packet.Direction.TO_STARBOUND_SERVER, ctx)); ChannelFuture f = starNubMainOutboundSocket.connect(starboundAddress, starboundPort); destinationCTX = f.channel().pipeline().firstContext(); if (destinationCTX != null) { new StarNubEvent("StarNub_Socket_Connection_Success_Server", ctx); StarNubProxyConnection.ConnectionProcessingType connectionProcessingType = null; if ((boolean) StarNub.getConfiguration().getNestedValue("advanced_settings", "packet_decoding")) { connectionProcessingType = StarNubProxyConnection.ConnectionProcessingType.PLAYER; } else {// w ww. j a va 2s.co m connectionProcessingType = StarNubProxyConnection.ConnectionProcessingType.PLAYER_NO_DECODING; } starNubProxyConnection = new StarNubProxyConnection(connectionProcessingType, ctx, destinationCTX); return true; } else { new StarNubEvent("StarNub_Socket_Connection_Failure_Cannot_Connect_Starbound", ctx); return false; } }
From source file:org.stem.client.old.StorageNodeClient.java
License:Apache License
private void initBootstrap() { bootstrap = new Bootstrap(); EventLoopGroup workerGroup = new NioEventLoopGroup(); bootstrap.group(workerGroup).channel(NioSocketChannel.class).option(ChannelOption.SO_KEEPALIVE, true) .option(ChannelOption.TCP_NODELAY, true) //.option(ChannelOption.SO_TIMEOUT, 100) .handler(new ChannelFactory()); }
From source file:org.stem.net.Server.java
License:Apache License
public void start() { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).childOption(ChannelOption.SO_KEEPALIVE, true) .option(ChannelOption.TCP_NODELAY, true).handler(new LoggingHandler(LogLevel.TRACE)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override/*from w w w . j av a 2 s . c o m*/ protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new PacketDecoder()).addLast(new PacketEncoder()) .addLast(new MessageDecoder()).addLast(new MessageEncoder()) .addLast(new MessageDispatcher()); } }); try { future = bootstrap.bind(socket).sync(); logger.info("Starting listening for clients on {}...", socket); channel = future.channel(); // Wait until server socket is closed. // channel.closeFuture().sync(); } catch (InterruptedException e) { e.printStackTrace(); throw new RuntimeException("Can't start server: ", e); } }
From source file:org.teiid.transport.SocketListener.java
License:Apache License
public SocketListener(final InetSocketAddress address, final int inputBufferSize, final int outputBufferSize, int maxWorkers, final SSLConfiguration config, final ClientServiceRegistryImpl csr, final StorageManager storageManager) { if (config != null) { this.isClientEncryptionEnabled = config.isClientEncryptionEnabled(); }/* w w w .ja v a2 s .com*/ this.csr = csr; NamedThreadFactory nettyPool = new NamedThreadFactory("NIO"); //$NON-NLS-1$ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_TRANSPORT, MessageLevel.DETAIL)) { LogManager.logDetail(LogConstants.CTX_TRANSPORT, "server = " + address.getAddress() + "binding to port:" + address.getPort()); //$NON-NLS-1$ //$NON-NLS-2$ } if (maxWorkers == 0) { maxWorkers = Math.max(4, PropertiesUtils.getIntProperty(System.getProperties(), "io.netty.eventLoopThreads", 2 * Runtime.getRuntime().availableProcessors())); //$NON-NLS-1$ } EventLoopGroup workers = new NioEventLoopGroup(maxWorkers, nettyPool); bootstrap = new ServerBootstrap(); bootstrap.group(workers).channel(NioServerSocketChannel.class); this.channelHandler = createChannelHandler(); bootstrap.childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); configureChannelPipeline(pipeline, config, storageManager); } }); if (inputBufferSize != 0) { bootstrap.childOption(ChannelOption.SO_RCVBUF, new Integer(inputBufferSize)); } if (outputBufferSize != 0) { bootstrap.childOption(ChannelOption.SO_SNDBUF, new Integer(outputBufferSize)); } bootstrap.childOption(ChannelOption.TCP_NODELAY, Boolean.TRUE); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, Boolean.TRUE); ChannelFuture future = bootstrap.bind(address); future.syncUninterruptibly(); this.serverChannel = future.channel(); }
From source file:org.tiger.netty.http.xml.client.HttpXmlClient.java
License:Apache License
public void connect(int port) throws Exception { // ?NIO//from w ww. j av a2 s .co m EventLoopGroup group = new NioEventLoopGroup(); try { Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true) .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast("http-decoder", new HttpResponseDecoder()); ch.pipeline().addLast("http-aggregator", new HttpObjectAggregator(65536)); // XML? ch.pipeline().addLast("xml-decoder", new HttpXmlResponseDecoder(Order.class, true)); //? ch.pipeline().addLast("http-encoder", new HttpRequestEncoder()); ch.pipeline().addLast("xml-encoder", new HttpXmlRequestEncoder()); ch.pipeline().addLast("xmlClientHandler", new HttpXmlClientHandle()); } }); // ?? ChannelFuture f = b.connect(new InetSocketAddress(port)).sync(); // f.channel().closeFuture().sync(); } finally { // NIO group.shutdownGracefully(); } }
From source file:org.tiger.netty.rpc.all.client.NettyClient.java
License:Apache License
public void connect(int port, String host) throws Exception { try {// w w w.j av a2 s .c om //Netty? Bootstrap b = new Bootstrap(); b.group(group) //Channel .channel(NioSocketChannel.class) //TCP?NIO?BIO????? //SO_TIMEOUT:??0?? //SO_SNDBUF:??? //SO_RCVBUF:? //SO_REUSEADDR:??ServerSocket???ServerSocketServerSocket?? //SO_REUSEADDR???????????? //CONNECT_TIMEOUT_MILLIS:NIO????Netty //TCP_NODELAY:?TCP_NODELAY?Nagle?Nagle .option(ChannelOption.TCP_NODELAY, true).handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { //new LengthFieldBasedFrameDecoder(100000000,0,4,0,4) //?? //??????030 //??44 //??? //????4???? ch.pipeline().addLast(new NettyMessageDecoder(1024 * 1024, 4, 4)); ch.pipeline().addLast("MessageEncoder", new NettyMessageEncoder());//Handler ch.pipeline().addLast("readTimeoutHandler", new ReadTimeoutHandler(50)); ch.pipeline().addLast("LoginAuthHandler", new LoginAuthReqHandler()); ch.pipeline().addLast("HeartBeatHandler", new HeartBeatReqHandler()); } }); //?????NioSocketChannel? //????????????? ChannelFuture future = b.connect(new InetSocketAddress(host, port), new InetSocketAddress(NettyConstant.LOCALIP, NettyConstant.LOCAL_PORT)).sync(); future.channel().closeFuture().sync(); } finally { // ???????? executor.execute(new Runnable() { public void run() { try { TimeUnit.SECONDS.sleep(1); try { connect(NettyConstant.PORT, NettyConstant.REMOTEIP);// ??? } catch (Exception e) { e.printStackTrace(); } } catch (InterruptedException e) { e.printStackTrace(); } } }); } }