List of usage examples for io.netty.bootstrap ServerBootstrap childHandler
ChannelHandler childHandler
To view the source code for io.netty.bootstrap ServerBootstrap childHandler.
Click Source Link
From source file:com.outbrain.pajamasproxy.memcached.server.MemCacheDaemon.java
License:Apache License
private void createBootstratp() { log.info("Initializing TCP..."); ServerBootstrap tcpBootstrap = new ServerBootstrap(); tcpBootstrap.group(eventLoopGroup);/*from w ww .jav a 2 s. com*/ tcpBootstrap.channel(NioServerSocketChannel.class); tcpBootstrap.childHandler(serverPipelineFactory); final ChannelFuture channelFuture = tcpBootstrap.bind(addr).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { log.info("Server started; listening to {}", addr); running = true; } }); }
From source file:com.qq.servlet.demo.netty.sample.myprotocol.MyProtocolServer.java
License:Apache License
public void run() throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(3); try {/* www .j a v a2 s.co m*/ final ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup); b.channel(NioServerSocketChannel.class); b.childHandler(new MyProtocolServerChannelHandler()); new Thread() { @Override public void run() { Channel channel; try { System.out.println("server is starting...."); channel = b.bind(port).sync().channel(); channel.closeFuture().sync(); } catch (InterruptedException e) { e.printStackTrace(); } } }.start(); } finally { byte[] b = new byte[32]; String read = null; do { if (read != null) System.out.println("" + read); int c = System.in.read(b); read = new String(b, 0, c); } while (read == null || !read.startsWith("exit")); bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.qq.servlet.demo.netty.sample.objectecho.ObjectEchoServer.java
License:Apache License
public void run() throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(2); EventLoopGroup workerGroup = new NioEventLoopGroup(3); try {/*from w ww .ja va2 s.co m*/ ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup); b.channel(NioServerSocketChannel.class); b.childHandler(new ObjectServerChannelHandler()); System.out.println("start server..."); // Bind and start to accept incoming connections. Channel channel = b.bind(port).sync().channel(); //waitting for close this server channel channel.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.qq.servlet.demo.netty.sample.telnet.TelnetServer.java
License:Apache License
public void run() throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/*from ww w . java2 s. c o m*/ ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup); b.channel(NioServerSocketChannel.class); b.childHandler(new TelnetServerInitializer()); b.bind(port).sync().channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.qq.servlet.demo.netty.sample.thrift.service.ThriftProtocolServer.java
License:Apache License
public void run() throws Exception { final EventLoopGroup bossGroup = new NioEventLoopGroup(1); final EventLoopGroup workerGroup = new NioEventLoopGroup(3); startCloseCmdThread(bossGroup, workerGroup); try {//from w w w .ja va2s .c om final ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup); b.channel(NioServerSocketChannel.class); b.childHandler(new ThriftProtocolServerChannelHandler()); Channel channel; System.out.println("server is starting...."); channel = b.bind(port).sync().channel(); channel.closeFuture().sync(); System.out.println("server is closing...."); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); System.out.println("server is closed"); } }
From source file:com.qq.servlet.demo.netty.telnet.TelnetServer.java
License:Apache License
public void run() throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(5); EventLoopGroup workerGroup = new NioEventLoopGroup(500); try {/* ww w .j ava 2 s . com*/ ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup); b.channel(NioServerSocketChannel.class); b.childHandler(new TelnetServerInitializer()); b.bind(port).sync().channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.quavo.osrs.network.NetworkExecutor.java
License:Open Source License
/** * Starts the network for a {@link Server}. * // w ww .j a va2s .co m * @param server The {@link Server} to use for building the network. * @return <True> If the network started successfully. */ public static void start() { EventLoopGroup boss = new NioEventLoopGroup(); EventLoopGroup worker = new NioEventLoopGroup(); ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(boss, worker); bootstrap.channel(NioServerSocketChannel.class); bootstrap.childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("decoder", new ConnectionDecoder()); pipeline.addLast("encoder", new ConnectionEncoder()); pipeline.addLast("adapter", new NetworkMessageHandler()); } }); bootstrap.childOption(ChannelOption.TCP_NODELAY, true); try { bootstrap.bind(Constants.HOST_NAME, Constants.HOST_PORT).sync(); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Server successfully bootstrapped on port " + Constants.HOST_PORT + " and address " + Constants.HOST_NAME + "."); }
From source file:com.relayrides.pushy.apns.MockApnsServer.java
License:Open Source License
public synchronized void start() throws InterruptedException { final ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(this.eventLoopGroup); bootstrap.channel(NioServerSocketChannel.class); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true); final MockApnsServer server = this; bootstrap.childHandler(new ChannelInitializer<SocketChannel>() { @Override// ww w.ja v a 2 s . co m protected void initChannel(final SocketChannel channel) throws Exception { channel.pipeline().addLast("ssl", new SslHandler(SSLTestUtil.createSSLEngineForMockServer())); channel.pipeline().addLast("encoder", new ApnsErrorEncoder()); channel.pipeline().addLast("decoder", new ApnsPushNotificationDecoder()); channel.pipeline().addLast("handler", new MockApnsServerHandler(server)); } }); this.channel = bootstrap.bind(this.port).await().channel(); }
From source file:com.relayrides.pushy.apns.MockFeedbackServer.java
License:Open Source License
public synchronized void start() throws InterruptedException { final ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(this.eventLoopGroup); bootstrap.channel(NioServerSocketChannel.class); final MockFeedbackServer server = this; bootstrap.childHandler(new ChannelInitializer<SocketChannel>() { @Override/*from ww w . jav a 2 s . c om*/ protected void initChannel(final SocketChannel channel) throws Exception { channel.pipeline().addLast("ssl", new SslHandler(SSLTestUtil.createSSLEngineForMockServer())); channel.pipeline().addLast("encoder", new ExpiredTokenEncoder()); channel.pipeline().addLast("handler", new MockFeedbackServerHandler(server)); } }); this.channel = bootstrap.bind(this.port).await().channel(); }
From source file:com.Server.java
License:Apache License
/** * This is passive mode server// w w w . ja va 2s . c o m * @param fs FTP Session Handler * @param host Server IP address * @param port Passive port no. */ public Server(String host, int port, int mode, String fileName) { InetSocketAddress inSocketAddress = new InetSocketAddress(host, port); try { ServerBootstrap bootStrap = new ServerBootstrap(); bootStrap.group(bossGroup, workerGroup); bootStrap.channel(NioServerSocketChannel.class); bootStrap.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 1); bootStrap.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 1); bootStrap.childHandler(new MyChannelInitializer(this, mode, fileName)); bootStrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); bootStrap.bind(inSocketAddress); System.out.println("Server started"); } catch (Exception eg) { eg.printStackTrace(); stop(); } }