/** * @see #localAddress(SocketAddress) */ public B localAddress(String inetHost, int inetPort) { return localAddress(SocketUtils.socketAddress(inetHost, inetPort)); }
/** * Create a new {@link Channel} and bind it. */ public ChannelFuture bind(String inetHost, int inetPort) { return bind(SocketUtils.socketAddress(inetHost, inetPort)); }
/** * @see #localAddress(SocketAddress) */ public B localAddress(String inetHost, int inetPort) { return localAddress(SocketUtils.socketAddress(inetHost, inetPort)); }
/** * Create a new {@link Channel} and bind it. */ public ChannelFuture bind(String inetHost, int inetPort) { return bind(SocketUtils.socketAddress(inetHost, inetPort)); }
/** * @see #localAddress(SocketAddress) */ public B localAddress(String inetHost, int inetPort) { return localAddress(SocketUtils.socketAddress(inetHost, inetPort)); }
/** * Create a new {@link Channel} and bind it. */ public ChannelFuture bind(String inetHost, int inetPort) { return bind(SocketUtils.socketAddress(inetHost, inetPort)); }
defaultNameServers.add(SocketUtils.socketAddress(uri.getHost(), port == -1 ? defaultPort : port)); } catch (URISyntaxException e) {
maybeIP = maybeIP.substring(0, i); addresses.add(SocketUtils.socketAddress(maybeIP, port)); } else if (line.startsWith(DOMAIN_ROW_LABEL)) { int i = indexOfNonWhiteSpace(line, DOMAIN_ROW_LABEL.length());
maybeIP = maybeIP.substring(0, i); addresses.add(SocketUtils.socketAddress(maybeIP, port)); } else if (line.startsWith(DOMAIN_ROW_LABEL)) { int i = indexOfNonWhiteSpace(line, DOMAIN_ROW_LABEL.length());
maybeIP = maybeIP.substring(0, i); addresses.add(SocketUtils.socketAddress(maybeIP, port)); } else if (line.startsWith(DOMAIN_ROW_LABEL)) { int i = indexOfNonWhiteSpace(line, DOMAIN_ROW_LABEL.length());
maybeIP = maybeIP.substring(0, i); addresses.add(SocketUtils.socketAddress(maybeIP, port)); } else if (line.startsWith(DOMAIN_ROW_LABEL)) { int i = indexOfNonWhiteSpace(line, DOMAIN_ROW_LABEL.length());
/** * @see #localAddress(SocketAddress) */ public B localAddress(String inetHost, int inetPort) { return localAddress(SocketUtils.socketAddress(inetHost, inetPort)); }
/** * Create a new {@link Channel} and bind it. */ public ChannelFuture bind(String inetHost, int inetPort) { return bind(SocketUtils.socketAddress(inetHost, inetPort)); }
/** * Create a new {@link Channel} and bind it. */ public ChannelFuture bind(String inetHost, int inetPort) { return bind(SocketUtils.socketAddress(inetHost, inetPort)); }
/** * @see #localAddress(SocketAddress) */ public B localAddress(String inetHost, int inetPort) { return localAddress(SocketUtils.socketAddress(inetHost, inetPort)); }
/** * @see #localAddress(SocketAddress) */ public B localAddress(String inetHost, int inetPort) { return localAddress(SocketUtils.socketAddress(inetHost, inetPort)); }
private ChannelFuture doConnect(final String[] hosts,final int idx ,final int port ,final SocketAddress localaddress){ if(idx>=hosts.length){ logger.error("hosts.length is {} ,but idx is {}.",hosts.length,idx); return null; } ChannelFuture future = bootstrap.connect(SocketUtils.socketAddress(hosts[idx],port),localaddress); future.addListener(new GenericFutureListener<ChannelFuture>(){ @Override public void operationComplete(ChannelFuture f) throws Exception { if(!f.isSuccess()){ if(idx+1 < hosts.length){ logger.info("retry connect to next host {}:{}",hosts[idx+1],port); doConnect(hosts,idx+1, port,localaddress); }else{ logger.error("Connect to {}:{} failed. cause by {}.",getEndpointEntity().getHost(),port,f.cause().getMessage()); } } }}); return future; }
/** * Create a new {@link Channel} and bind it. */ public ChannelFuture bind(String inetHost, int inetPort) { return bind(SocketUtils.socketAddress(inetHost, inetPort)); }
public void start() throws InterruptedException { this.bossGroup = new NioEventLoopGroup(); this.parsers.forEach(parser -> parser.start(this.bossGroup)); final InetSocketAddress address = this.host != null ? SocketUtils.socketAddress(this.host, this.port) : new InetSocketAddress(this.port); this.socketFuture = new Bootstrap() .group(this.bossGroup) .channel(NioDatagramChannel.class) .option(ChannelOption.SO_REUSEADDR, true) .option(ChannelOption.SO_RCVBUF, Integer.MAX_VALUE) .option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(this.maxPacketSize)) .handler(new DefaultChannelInitializer()) .bind(address) .sync(); }
@Override public ChannelFuture open() throws Exception { String host = getEndpointEntity().getHost(); String localhost = getEndpointEntity().getLocalhost(); Integer localport = getEndpointEntity().getLocalport(); SocketAddress localaddr = null; if(StringUtils.isNotBlank(localhost) && localport!=null){ localaddr = SocketUtils.socketAddress(localhost, localport); } if(StringUtils.isBlank(host)){ logger.error("remote host is blank"); return null; } return doConnect(host.split(","),0,getEndpointEntity().getPort(),localaddr); }