io.netty.bootstrap.Bootstrap.localAddress()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(355)

本文整理了Java中io.netty.bootstrap.Bootstrap.localAddress()方法的一些代码示例,展示了Bootstrap.localAddress()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bootstrap.localAddress()方法的具体详情如下:
包路径:io.netty.bootstrap.Bootstrap
类名称:Bootstrap
方法名:localAddress

Bootstrap.localAddress介绍

暂无

代码示例

代码示例来源:origin: normanmaurer/netty-in-action

public LogEventMonitor(InetSocketAddress address) {
  group = new NioEventLoopGroup();
  bootstrap = new Bootstrap();
  bootstrap.group(group)
    .channel(NioDatagramChannel.class)
    .option(ChannelOption.SO_BROADCAST, true)
    .handler( new ChannelInitializer<Channel>() {
      @Override
      protected void initChannel(Channel channel)
        throws Exception {
        ChannelPipeline pipeline = channel.pipeline();
        pipeline.addLast(new LogEventDecoder());
        pipeline.addLast(new LogEventHandler());
      }
    } )
    .localAddress(address);
}

代码示例来源:origin: atomix/atomix

.option(ChannelOption.IP_MULTICAST_IF, iface)
.option(ChannelOption.SO_REUSEADDR, true)
.localAddress(localAddress.getPort());

代码示例来源:origin: eclipse-vertx/vert.x

public void configure(ClientOptionsBase options, boolean domainSocket, Bootstrap bootstrap) {
 if (!domainSocket) {
  bootstrap.option(ChannelOption.SO_REUSEADDR, options.isReuseAddress());
  bootstrap.option(ChannelOption.TCP_NODELAY, options.isTcpNoDelay());
  bootstrap.option(ChannelOption.SO_KEEPALIVE, options.isTcpKeepAlive());
 }
 if (options.getLocalAddress() != null) {
  bootstrap.localAddress(options.getLocalAddress(), 0);
 }
 if (options.getSendBufferSize() != -1) {
  bootstrap.option(ChannelOption.SO_SNDBUF, options.getSendBufferSize());
 }
 if (options.getReceiveBufferSize() != -1) {
  bootstrap.option(ChannelOption.SO_RCVBUF, options.getReceiveBufferSize());
  bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(options.getReceiveBufferSize()));
 }
 if (options.getSoLinger() != -1) {
  bootstrap.option(ChannelOption.SO_LINGER, options.getSoLinger());
 }
 if (options.getTrafficClass() != -1) {
  bootstrap.option(ChannelOption.IP_TOS, options.getTrafficClass());
 }
 bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, options.getConnectTimeout());
 bootstrap.option(ChannelOption.ALLOCATOR, PartialPooledByteBufAllocator.INSTANCE);
}

代码示例来源:origin: SpigotMC/BungeeCord

public void start(Class<? extends Channel> channel, InetSocketAddress address, EventLoopGroup eventLoop, ChannelFutureListener future)
  {
    new Bootstrap()
        .channel( channel )
        .group( eventLoop )
        .handler( new QueryHandler( bungee, listener ) )
        .localAddress( address )
        .bind().addListener( future );
  }
}

代码示例来源:origin: io.vertx/vertx-core

public void configure(ClientOptionsBase options, boolean domainSocket, Bootstrap bootstrap) {
 if (!domainSocket) {
  bootstrap.option(ChannelOption.SO_REUSEADDR, options.isReuseAddress());
  bootstrap.option(ChannelOption.TCP_NODELAY, options.isTcpNoDelay());
  bootstrap.option(ChannelOption.SO_KEEPALIVE, options.isTcpKeepAlive());
 }
 if (options.getLocalAddress() != null) {
  bootstrap.localAddress(options.getLocalAddress(), 0);
 }
 if (options.getSendBufferSize() != -1) {
  bootstrap.option(ChannelOption.SO_SNDBUF, options.getSendBufferSize());
 }
 if (options.getReceiveBufferSize() != -1) {
  bootstrap.option(ChannelOption.SO_RCVBUF, options.getReceiveBufferSize());
  bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(options.getReceiveBufferSize()));
 }
 if (options.getSoLinger() != -1) {
  bootstrap.option(ChannelOption.SO_LINGER, options.getSoLinger());
 }
 if (options.getTrafficClass() != -1) {
  bootstrap.option(ChannelOption.IP_TOS, options.getTrafficClass());
 }
 bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, options.getConnectTimeout());
 bootstrap.option(ChannelOption.ALLOCATOR, PartialPooledByteBufAllocator.INSTANCE);
}

代码示例来源:origin: SpigotMC/BungeeCord

b.localAddress( getPendingConnection().getListener().getHost().getHostString(), 0 );

代码示例来源:origin: reactor/reactor-netty

/**
 * The address to which this server should bind on subscribe.
 *
 * @param bindingAddressSupplier A supplier of the address to bind to.
 *
 * @return a new {@link UdpServer}
 */
public final UdpServer addressSupplier(Supplier<? extends SocketAddress> bindingAddressSupplier) {
  Objects.requireNonNull(bindingAddressSupplier, "bindingAddressSupplier");
  return bootstrap(b -> b.localAddress(bindingAddressSupplier.get()));
}

代码示例来源:origin: ribasco/async-gamequery-lib

@Override
  protected ChannelFuture connectChannel(Bootstrap bs) {
    return bs.localAddress(0).bind();
  }
}

代码示例来源:origin: io.projectreactor.netty/reactor-netty

/**
 * The address to which this server should bind on subscribe.
 *
 * @param bindingAddressSupplier A supplier of the address to bind to.
 *
 * @return a new {@link UdpServer}
 */
public final UdpServer addressSupplier(Supplier<? extends SocketAddress> bindingAddressSupplier) {
  Objects.requireNonNull(bindingAddressSupplier, "bindingAddressSupplier");
  return bootstrap(b -> b.localAddress(bindingAddressSupplier.get()));
}

代码示例来源:origin: ribasco/async-gamequery-lib

/**
 * Start listening for log messages
 */
public void listen() throws InterruptedException {
  final ChannelFuture bindFuture = bootstrap.localAddress(listenAddress).bind().await();
  bindFuture.addListener((ChannelFuture future) -> {
    String hostAddress = ((InetSocketAddress) future.channel().localAddress()).getAddress().getHostAddress();
    int port = ((InetSocketAddress) future.channel().localAddress()).getPort();
    log.debug("Log Service listening on port {} via address {}", port, hostAddress);
    future.channel().closeFuture().addListener(future1 -> log.debug("Service Shutting Down"));
  });
}

代码示例来源:origin: WaterfallMC/Waterfall-Old

public void start(Class<? extends Channel> channel, InetSocketAddress address, EventLoopGroup eventLoop, ChannelFutureListener future)
  {
    new Bootstrap()
        .channel( channel )
        .group( eventLoop )
        .handler( new QueryHandler( bungee, listener ) )
        .localAddress( address )
        .bind().addListener( future );
  }
}

代码示例来源:origin: reactor/reactor-netty

/**
 * The host to which this server should bind.
 *
 * @param host The host to bind to.
 *
 * @return a new {@link UdpServer}
 */
public final UdpServer host(String host) {
  Objects.requireNonNull(host, "host");
  return bootstrap(b -> b.localAddress(host, getPort(b)));
}

代码示例来源:origin: io.projectreactor.netty/reactor-netty

/**
 * The host to which this server should bind.
 *
 * @param host The host to bind to.
 *
 * @return a new {@link UdpServer}
 */
public final UdpServer host(String host) {
  Objects.requireNonNull(host, "host");
  return bootstrap(b -> b.localAddress(host, getPort(b)));
}

代码示例来源:origin: org.opendaylight.bgpcep/bgp-rib-impl

public Future<BGPSessionImpl> createClient(final InetSocketAddress localAddress, final InetSocketAddress remoteAddress,
    final StrictBGPPeerRegistry strictBGPPeerRegistry, final int retryTimer) {
  final Bootstrap clientBootStrap = createClientBootStrap(Optional.<KeyMapping>absent(), this.workerGroup);
  clientBootStrap.localAddress(localAddress);
  return createClient(remoteAddress, strictBGPPeerRegistry, retryTimer, clientBootStrap);
}

代码示例来源:origin: io.projectreactor.netty/reactor-netty

/**
 * The port to which this server should bind.
 *
 * @param port The port to bind to.
 *
 * @return a new {@link UdpServer}
 */
public final UdpServer port(int port) {
  return bootstrap(b -> b.localAddress(getHost(b), port));
}

代码示例来源:origin: reactor/reactor-netty

/**
 * The port to which this server should bind.
 *
 * @param port The port to bind to.
 *
 * @return a new {@link UdpServer}
 */
public final UdpServer port(int port) {
  return bootstrap(b -> b.localAddress(getHost(b), port));
}

代码示例来源:origin: VelocityPowered/Velocity

/**
 * Binds a GS4 listener to the specified {@code hostname} and {@code port}.
 *
 * @param hostname the hostname to bind to
 * @param port the port to bind to
 */
public void queryBind(final String hostname, final int port) {
 InetSocketAddress address = new InetSocketAddress(hostname, port);
 final Bootstrap bootstrap = new Bootstrap()
   .channel(this.transportType.datagramChannelClass)
   .group(this.workerGroup)
   .handler(new GS4QueryHandler(this.server))
   .localAddress(address);
 bootstrap.bind()
   .addListener((ChannelFutureListener) future -> {
    final Channel channel = future.channel();
    if (future.isSuccess()) {
     this.endpoints.put(address, channel);
     LOGGER.info("Listening for GS4 query on {}", channel.localAddress());
    } else {
     LOGGER.error("Can't bind to {}", bootstrap.config().localAddress(), future.cause());
    }
   });
}

代码示例来源:origin: com.wavefront/java-lib

.group(group)
.channel(datagramChannelClass)
.localAddress(listeningPort)
.handler(initializer);

代码示例来源:origin: apache/qpid-jms

private void configureNetty(Bootstrap bootstrap, TransportOptions options) {
  bootstrap.option(ChannelOption.TCP_NODELAY, options.isTcpNoDelay());
  bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, options.getConnectTimeout());
  bootstrap.option(ChannelOption.SO_KEEPALIVE, options.isTcpKeepAlive());
  bootstrap.option(ChannelOption.SO_LINGER, options.getSoLinger());
  if (options.getSendBufferSize() != -1) {
    bootstrap.option(ChannelOption.SO_SNDBUF, options.getSendBufferSize());
  }
  if (options.getReceiveBufferSize() != -1) {
    bootstrap.option(ChannelOption.SO_RCVBUF, options.getReceiveBufferSize());
    bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(options.getReceiveBufferSize()));
  }
  if (options.getTrafficClass() != -1) {
    bootstrap.option(ChannelOption.IP_TOS, options.getTrafficClass());
  }
  if (options.getLocalAddress() != null || options.getLocalPort() != 0) {
    if(options.getLocalAddress() != null) {
      bootstrap.localAddress(options.getLocalAddress(), options.getLocalPort());
    } else {
      bootstrap.localAddress(options.getLocalPort());
    }
  }
}

代码示例来源:origin: io.projectreactor.ipc/reactor-netty

@Override
public Mono<? extends NettyContext> newHandler(BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>> handler) {
  final BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>>
      targetHandler =
      null == handler ? ChannelOperations.noopHandler() : handler;
  return Mono.create(sink -> {
    Bootstrap b = options.get();
    SocketAddress adr = options.getAddress();
    if(adr == null){
      sink.error(new NullPointerException("Provided UdpServerOptions do not " +
          "define any address to bind to "));
      return;
    }
    b.localAddress(adr);
    ContextHandler<DatagramChannel> c = doHandler(targetHandler, sink, adr);
    b.handler(c);
    c.setFuture(b.bind());
  });
}

相关文章