public void init() { bootstrap = new Bootstrap(); bootstrap.group(new OioEventLoopGroup()) .channel(OioSocketChannel.class) .option(ChannelOption.SO_KEEPALIVE, true) .option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeout) .handler(new FileClientChannelInitializer(handler)); }
public FileServer(PathResolver pResolver, int port) { InetSocketAddress addr = new InetSocketAddress(port); // Configure the server. bootstrap = new ServerBootstrap(); bootstrap.group(new OioEventLoopGroup(), new OioEventLoopGroup()) .channel(OioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100) .option(ChannelOption.SO_RCVBUF, 1500) .childHandler(new FileServerChannelInitializer(pResolver)); // Start the server. channelFuture = bootstrap.bind(addr); try { // Get the address we bound to. InetSocketAddress boundAddress = ((InetSocketAddress) channelFuture.sync().channel().localAddress()); this.port = boundAddress.getPort(); } catch (InterruptedException ie) { this.port = 0; } }
/** * Listing 8.8 Using Bootstrap with DatagramChannel */ public void bootstrap() { Bootstrap bootstrap = new Bootstrap(); bootstrap.group(new OioEventLoopGroup()).channel( OioDatagramChannel.class).handler( new SimpleChannelInboundHandler<DatagramPacket>() { @Override public void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception { // Do something with the packet } } ); ChannelFuture future = bootstrap.bind(new InetSocketAddress(0)); future.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture channelFuture) throws Exception { if (channelFuture.isSuccess()) { System.out.println("Channel bound"); } else { System.err.println("Bind attempt failed"); channelFuture.cause().printStackTrace(); } } }); } }
final ByteBuf buf = Unpooled.unreleasableBuffer(Unpooled.copiedBuffer("Hi!\r\n", Charset.forName("UTF-8"))); EventLoopGroup group = new OioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap();
Class<? extends ServerChannel> socketClass = null; if (singleThreadPerConnection) { bossGroup = new OioEventLoopGroup(Integer.MAX_VALUE, selectorThreadFactory); workerGroup = new OioEventLoopGroup(Integer.MAX_VALUE, workerThreadFactory); socketClass = OioServerSocketChannel.class; } else {
@Override public Channel createChannel(ChannelHandler channelHandler) throws PlcConnectionException { JSerialCommDeviceAddress address = new JSerialCommDeviceAddress(serialPort); try { Bootstrap bootstrap = new Bootstrap(); bootstrap.group(new OioEventLoopGroup()); bootstrap.channel(JSerialCommChannel.class); bootstrap.option(ChannelOption.SO_KEEPALIVE, true); bootstrap.option(ChannelOption.TCP_NODELAY, true); bootstrap.handler(channelHandler); // Start the client. ChannelFuture f = bootstrap.connect(address).sync(); f.awaitUninterruptibly(); // Wait till the session is finished initializing. return f.channel(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PlcConnectionException("Error creating channel.", e); } }
eventLoopGroup = new OioEventLoopGroup(); bootstrap.group(eventLoopGroup); bootstrap.channel(JSerialCommChannel.class);
final Bootstrap bootstrap = new Bootstrap(); if(this.proxy != null) { this.group = new OioEventLoopGroup(); bootstrap.channelFactory(new ProxyOioChannelFactory(this.proxy)); } else {
Class<? extends ServerChannel> socketClass = null; if (singleThreadPerConnection) { bossGroup = new OioEventLoopGroup(Integer.MAX_VALUE, selectorThreadFactory); workerGroup = new OioEventLoopGroup(Integer.MAX_VALUE, workerThreadFactory); socketClass = OioServerSocketChannel.class; } else {