/** * @return a new datagram channel */ public DatagramChannel datagramChannel() { return new NioDatagramChannel(); }
/** * @return a new datagram channel */ public DatagramChannel datagramChannel(InternetProtocolFamily family) { switch (family) { case IPv4: return new NioDatagramChannel(InternetProtocolFamily.IPv4); case IPv6: return new NioDatagramChannel(InternetProtocolFamily.IPv6); default: throw new UnsupportedOperationException(); } }
@Override public DatagramChannel newChannel() { switch (transportType) { case EPOLL: return new EpollDatagramChannel(); case KQUEUE: return new KQueueDatagramChannel(); case NIO: return new NioDatagramChannel(); default: throw new IllegalArgumentException("Invalid or unknown Netty transport type " + transportType); } } }
private CompletableFuture<Void> bootstrapServer() { Bootstrap serverBootstrap = new Bootstrap() .group(group) .channelFactory(() -> new NioDatagramChannel(InternetProtocolFamily.IPv4)) .handler(new SimpleChannelInboundHandler<Object>() { @Override public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { // Nothing will be sent. } }) .option(ChannelOption.IP_MULTICAST_IF, iface) .option(ChannelOption.SO_REUSEADDR, true); CompletableFuture<Void> future = new CompletableFuture<>(); serverBootstrap.bind(localAddress).addListener((ChannelFutureListener) f -> { if (f.isSuccess()) { serverChannel = f.channel(); future.complete(null); } else { future.completeExceptionally(f.cause()); } }); return future; }
private CompletableFuture<Void> bootstrapClient() { Bootstrap clientBootstrap = new Bootstrap() .group(group) .channelFactory(() -> new NioDatagramChannel(InternetProtocolFamily.IPv4)) .handler(new SimpleChannelInboundHandler<DatagramPacket>() { @Override
private void createNioServer(Listener listener) { NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup( 1, new DefaultThreadFactory(ThreadNames.T_GATEWAY_WORKER) ); eventLoopGroup.setIoRatio(100); createServer(listener, eventLoopGroup, () -> new NioDatagramChannel(IPv4));//默认是根据机器情况创建Channel,如果机器支持ipv6,则无法使用ipv4的地址加入组播 }
/** * @return a new datagram channel */ public DatagramChannel datagramChannel() { return new NioDatagramChannel(); }
/** * @return a new datagram channel */ public DatagramChannel datagramChannel(InternetProtocolFamily family) { switch (family) { case IPv4: return new NioDatagramChannel(InternetProtocolFamily.IPv4); case IPv6: return new NioDatagramChannel(InternetProtocolFamily.IPv6); default: throw new UnsupportedOperationException(); } }
@Override public Channel newChannel() { return new NioDatagramChannel(InternetProtocolFamily.IPv4); } })
@Override public Channel newChannel() { return new NioDatagramChannel(InternetProtocolFamily.IPv4); } })
@Override public DatagramChannel newChannel() { return new NioDatagramChannel(); } };
@Override public Channel newChannel() { return new NioDatagramChannel(family); } });
private CompletableFuture<Void> bootstrapServer() { Bootstrap serverBootstrap = new Bootstrap() .group(group) .channelFactory(() -> new NioDatagramChannel(InternetProtocolFamily.IPv4)) .handler(new SimpleChannelInboundHandler<Object>() { @Override public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { // Nothing will be sent. } }) .option(ChannelOption.IP_MULTICAST_IF, iface) .option(ChannelOption.SO_REUSEADDR, true); CompletableFuture<Void> future = new CompletableFuture<>(); serverBootstrap.bind(localAddress).addListener((ChannelFutureListener) f -> { if (f.isSuccess()) { serverChannel = f.channel(); future.complete(null); } else { future.completeExceptionally(f.cause()); } }); return future; }
@Override protected Bootstrap configure() { Bootstrap b = source.configure(); boolean useNative = family == null && preferNative; EventLoopGroup elg = loopResources.onClient(useNative); if (useNative) { b.channel(loopResources.onDatagramChannel(elg)); } else { b.channelFactory(() -> new NioDatagramChannel(family)); } return b.group(elg); } }
@Override protected Bootstrap configure() { Bootstrap b = source.configure(); boolean useNative = family == null && preferNative; EventLoopGroup elg = loopResources.onClient(useNative); if (useNative) { b.channel(loopResources.onDatagramChannel(elg)); } else { b.channelFactory(() -> new NioDatagramChannel(family)); } return b.group(elg); } }
@Override protected Bootstrap configure() { Bootstrap b = source.configure(); boolean useNative = family == null && preferNative; EventLoopGroup elg = loopResources.onClient(useNative); if (useNative) { b.channel(loopResources.onDatagramChannel(elg)); } else { b.channelFactory(() -> new NioDatagramChannel(family)); } return b.group(elg); } }
@Override protected Bootstrap configure() { Bootstrap b = source.configure(); boolean useNative = family == null && preferNative; EventLoopGroup elg = loopResources.onClient(useNative); if (useNative) { b.channel(loopResources.onDatagramChannel(elg)); } else { b.channelFactory(() -> new NioDatagramChannel(family)); } return b.group(elg); } }
@SuppressWarnings("unchecked") final void groupAndChannel(Bootstrap bootstrap) { LoopResources loops = Objects.requireNonNull(getLoopResources(), "loopResources"); boolean useNative = this.protocolFamily == null && preferNative() && !(sslContext() instanceof JdkSslContext); EventLoopGroup elg = loops.onClient(useNative); if (this.poolResources != null && elg instanceof Supplier) { //don't colocate bootstrap.group(((Supplier<EventLoopGroup>) elg).get()); } else { bootstrap.group(elg); } if (useDatagramChannel()) { if (useNative) { bootstrap.channel(loops.onDatagramChannel(elg)); } else { bootstrap.channelFactory(() -> new NioDatagramChannel(protocolFamily)); } } else { bootstrap.channel(loops.onChannel(elg)); } }
.getDatagramChannel(ioGroup)); } else { bootstrap.channelFactory(() -> new NioDatagramChannel(toNettyFamily(options.protocolFamily())));
@Override public Channel newChannel() { final NioDatagramChannel ch = new NioDatagramChannel(); DatagramChannelConfig config = ch.config(); config.setReceiveBufferSize(options.rcvbuf());