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:com.example.spring.boot.netty.TcpClient.java
License:Apache License
public void connectServer() { for (int i = 0; i < connNum; i++) { EventLoopGroup group = new NioEventLoopGroup(); try {/*from w ww.j a va2 s .c o m*/ 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 { ChannelPipeline p = ch.pipeline(); //p.addLast(new LoggingHandler(LogLevel.INFO)); p.addLast(new LineBasedFrameDecoder(1024)); p.addLast(new StringDecoder()); p.addLast(new TcpClientHandler(TcpClient.this)); } }); // Start the client. ChannelFuture f = b.connect(address.split(":")[0], Integer.parseInt(address.split(":")[1])).sync(); // Wait until the connection is closed. // f.channel().closeFuture().sync(); } catch (Throwable e) { e.printStackTrace(); } finally { // Shut down the event loop to terminate all threads. // group.shutdownGracefully(); } } }
From source file:com.farsunset.cim.sdk.android.CIMConnectorManager.java
License:Apache License
private CIMConnectorManager(Context ctx) { context = ctx;//from w w w . j a v a 2 s . co m bootstrap = new Bootstrap(); loopGroup = new NioEventLoopGroup(1); bootstrap.group(loopGroup); bootstrap.channel(NioSocketChannel.class); bootstrap.option(ChannelOption.TCP_NODELAY, true); bootstrap.option(ChannelOption.SO_KEEPALIVE, true); bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT); bootstrap.handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new ClientMessageDecoder()); ch.pipeline().addLast(new ClientMessageEncoder()); ch.pipeline().addLast(new IdleStateHandler(READ_IDLE_TIME, 0, 0)); ch.pipeline().addLast(CIMLoggingHandler.getLogger()); ch.pipeline().addLast(CIMConnectorManager.this); } }); }
From source file:com.farsunset.cim.sdk.client.CIMConnectorManager.java
License:Apache License
private CIMConnectorManager() { bootstrap = new Bootstrap(); loopGroup = new NioEventLoopGroup(); bootstrap.group(loopGroup);/* www . ja v a 2s .com*/ bootstrap.channel(NioSocketChannel.class); bootstrap.option(ChannelOption.TCP_NODELAY, true); bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT); bootstrap.handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(new ClientMessageDecoder()); pipeline.addLast(new ClientMessageEncoder()); pipeline.addLast(new IdleStateHandler(READ_IDLE_TIME, 0, 0)); pipeline.addLast(CIMConnectorManager.this); } }); }
From source file:com.farsunset.cim.sdk.server.handler.CIMNioSocketAcceptor.java
License:Apache License
public void bind() throws IOException { /**/* w ww . jav a2s . c om*/ * websocket?? */ innerHandlerMap.put(WEBSOCKET_HANDLER_KEY, new WebsocketHandler()); ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(new NioEventLoopGroup(), new NioEventLoopGroup()); bootstrap.childOption(ChannelOption.TCP_NODELAY, true); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true); bootstrap.channel(NioServerSocketChannel.class); bootstrap.childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new ServerMessageDecoder()); ch.pipeline().addLast(new ServerMessageEncoder()); ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO)); ch.pipeline().addLast(new IdleStateHandler(READ_IDLE_TIME, WRITE_IDLE_TIME, 0)); ch.pipeline().addLast(CIMNioSocketAcceptor.this); } }); bootstrap.bind(port); }
From source file:com.feihong.newzxclient.tcp.NettyClient.java
License:Apache License
@SuppressWarnings("unchecked") public void connect() throws Exception { mGroup = new NioEventLoopGroup(); Bootstrap b = new Bootstrap(); b.group(mGroup).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true) .handler(new ChannelInitializer<SocketChannel>() { @Override//from w ww.ja v a2 s.c o m public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast("decoder", new IntLengthDecoder()); ch.pipeline().addLast(new NettyClientHandler()); } }); ChannelFuture future = b.connect(host, port).sync(); future.addListeners(new ChannelFutureListener() { public void operationComplete(final ChannelFuture future) throws Exception { requestLogin(); } }); mChannel = future.channel(); mHandler = mChannel.pipeline().get(NettyClientHandler.class); }
From source file:com.flowpowered.network.NetworkServer.java
License:MIT License
public NetworkServer() { bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new BasicChannelInitializer(this)).childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.SO_KEEPALIVE, true); }
From source file:com.friz.audio.AudioServer.java
License:Open Source License
@Override public void initialize() { group = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors()); bootstrap = new ServerBootstrap(); AudioServer s = this; bootstrap.group(group).channel(NioServerSocketChannel.class) //.handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<NioSocketChannel>() { @Override/* ww w . j av a2s. c o m*/ protected void initChannel(NioSocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(HttpServerCodec.class.getName(), new HttpServerCodec()); p.addLast(HttpObjectAggregator.class.getName(), new HttpObjectAggregator(65536)); p.addLast(ChunkedWriteHandler.class.getName(), new ChunkedWriteHandler()); p.addLast(AudioChannelHandler.class.getName(), new AudioChannelHandler(s)); } }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.TCP_NODELAY, true); hub.listen(AudioRequestEvent.class, new AudioRequestEventListener()); service.startAsync(); }
From source file:com.friz.game.GameServer.java
License:Open Source License
@Override public void initialize() { group = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors()); bootstrap = new ServerBootstrap(); GameServer s = this; bootstrap.group(group).channel(NioServerSocketChannel.class) //.handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<NioSocketChannel>() { @Override//from w ww. ja v a2s. c o m protected void initChannel(NioSocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(LoginInitEncoder.class.getName(), new LoginInitEncoder()); p.addLast(LoginInitDecoder.class.getName(), new LoginInitDecoder()); p.addLast(GameChannelHandler.class.getName(), new GameChannelHandler(s)); } }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.TCP_NODELAY, true); }
From source file:com.friz.lobby.LobbyServer.java
License:Open Source License
@Override public void initialize() { group = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors()); bootstrap = new ServerBootstrap(); LobbyServer s = this; bootstrap.group(group).channel(NioServerSocketChannel.class) //.handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<NioSocketChannel>() { @Override//from w ww .ja va2s . c om protected void initChannel(NioSocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(LobbyInitEncoder.class.getName(), new LobbyInitEncoder()); p.addLast(LobbyInitDecoder.class.getName(), new LobbyInitDecoder()); p.addLast(LobbyChannelHandler.class.getName(), new LobbyChannelHandler(s)); } }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.TCP_NODELAY, true); eventHub.listen(LobbyInitRequestEvent.class, new LobbyInitEventListener()); eventHub.listen(SocialInitRequestEvent.class, new SocialInitEventListener()); eventHub.listen(CreationRequestEvent.class, new CreationEventListener()); eventHub.listen(LoginRequestEvent.class, new LoginRequestEventListener()); moduleHub.listen(ClientVersionModule.class, new ClientVersionModuleListener()); moduleHub.listen(ClientTypeModule.class, new ClientTypeModuleListener()); }
From source file:com.friz.login.LoginServer.java
License:Open Source License
@Override public void initialize() { group = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors()); bootstrap = new ServerBootstrap(); LoginServer s = this; bootstrap.group(group).channel(NioServerSocketChannel.class) //.handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<NioSocketChannel>() { @Override/*from w ww.j a v a 2s .c o m*/ protected void initChannel(NioSocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(IdleStateHandler.class.getName(), new IdleStateHandler(15, 0, 0)); p.addLast(LoginChannelHandler.class.getName(), new LoginChannelHandler(s)); } }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.TCP_NODELAY, true); }