/** * Creates a new connected channel with the specified * {@code "remoteAddress"} and the current {@code "localAddress"} option. * If the {@code "localAddress"} option is not set, the local address of * a new channel is determined automatically. This method is identical * with the following code: * * <pre> * {@link ConnectionlessBootstrap} b = ...; * b.connect(remoteAddress, b.getOption("localAddress")); * </pre> * * @return a future object which notifies when the creation of the connected * channel succeeds or fails * * @throws ClassCastException * if {@code "localAddress"} option's value is * neither a {@link SocketAddress} nor {@code null} * @throws ChannelPipelineException * if this bootstrap's {@link #setPipelineFactory(ChannelPipelineFactory) pipelineFactory} * failed to create a new {@link ChannelPipeline} */ public ChannelFuture connect(SocketAddress remoteAddress) { if (remoteAddress == null) { throw new NullPointerException("remotedAddress"); } SocketAddress localAddress = (SocketAddress) getOption("localAddress"); return connect(remoteAddress, localAddress); }
/** * Creates a new connected channel with the current {@code "remoteAddress"} * and {@code "localAddress"} option. If the {@code "localAddress"} option * is not set, the local address of a new channel is determined * automatically. This method is similar to the following code: * * <pre> * {@link ConnectionlessBootstrap} b = ...; * b.connect(b.getOption("remoteAddress"), b.getOption("localAddress")); * </pre> * * @return a future object which notifies when the creation of the connected * channel succeeds or fails * * @throws IllegalStateException * if {@code "remoteAddress"} option was not set * @throws ClassCastException * if {@code "remoteAddress"} or {@code "localAddress"} option's * value is neither a {@link SocketAddress} nor {@code null} * @throws ChannelPipelineException * if this bootstrap's {@link #setPipelineFactory(ChannelPipelineFactory) pipelineFactory} * failed to create a new {@link ChannelPipeline} */ public ChannelFuture connect() { SocketAddress remoteAddress = (SocketAddress) getOption("remoteAddress"); if (remoteAddress == null) { throw new IllegalStateException("remoteAddress option is not set."); } return connect(remoteAddress); }
/** * Creates a new channel which is bound to the local address which was * specified in the current {@code "localAddress"} option. This method is * similar to the following code: * * <pre> * {@link ConnectionlessBootstrap} b = ...; * b.bind(b.getOption("localAddress")); * </pre> * * @return a new bound channel which accepts incoming connections * * @throws IllegalStateException * if {@code "localAddress"} option was not set * @throws ClassCastException * if {@code "localAddress"} option's value is * neither a {@link SocketAddress} nor {@code null} * @throws ChannelException * if failed to create a new channel and * bind it to the local address */ public Channel bind() { SocketAddress localAddress = (SocketAddress) getOption("localAddress"); if (localAddress == null) { throw new IllegalStateException("localAddress option is not set."); } return bind(localAddress); }