/** * Create a inet socket address, {@code host} must be non {@code null} and {@code port} must be between {@code 0} * and {@code 65536}. * * @param port the address port * @param host the address host * @return the created socket address */ static SocketAddress inetSocketAddress(int port, String host) { return new SocketAddressImpl(port, host); }
/** * Create a domain socket address. * * @param path the address path * @return the created socket address */ static SocketAddress domainSocketAddress(String path) { return new SocketAddressImpl(path); }
public SocketAddress localAddress() { InetSocketAddress addr = (InetSocketAddress) chctx.channel().localAddress(); if (addr == null) return null; return new SocketAddressImpl(addr); }
public SocketAddress remoteAddress() { InetSocketAddress addr = (InetSocketAddress) chctx.channel().remoteAddress(); if (addr == null) return null; return new SocketAddressImpl(addr); }
@Override public SocketAddress sender() { if (senderAddress == null) { senderAddress = new SocketAddressImpl(sender.getPort(), sender.getAddress().getHostAddress()); } return senderAddress; }
@Override public SocketAddress localAddress() { InetSocketAddress addr = channel.localAddress(); return new SocketAddressImpl(addr); }
@Override public DatagramSocket listen(int port, String address, Handler<AsyncResult<DatagramSocket>> handler) { return listen(new SocketAddressImpl(port, address), handler); }
@Override @SuppressWarnings("unchecked") public DatagramSocket send(Buffer packet, int port, String host, Handler<AsyncResult<DatagramSocket>> handler) { Objects.requireNonNull(packet, "no null packet accepted"); Objects.requireNonNull(host, "no null host accepted"); if (port < 0 || port > 65535) { throw new IllegalArgumentException("port out of range:" + port); } context.owner().resolveAddress(host, res -> { if (res.succeeded()) { doSend(packet, new InetSocketAddress(res.result(), port), handler); } else { handler.handle(Future.failedFuture(res.cause())); } }); if (metrics != null) { metrics.bytesWritten(null, new SocketAddressImpl(port, host), packet.length()); } return this; }
@Test public void testSocketAddress() throws Exception { assertNullPointerException(() -> new SocketAddressImpl(0, null)); assertIllegalArgumentException(() -> new SocketAddressImpl(0, "")); assertIllegalArgumentException(() -> new SocketAddressImpl(-1, "someHost")); assertIllegalArgumentException(() -> new SocketAddressImpl(65536, "someHost")); }
VertxMetrics metrics = vertx.metricsSPI(); if (metrics != null) { this.metrics = metrics.createNetServerMetrics(options, new SocketAddressImpl(id.port, id.host)); this.actualPort = shared.actualPort(); VertxMetrics metrics = vertx.metricsSPI(); this.metrics = metrics != null ? metrics.createNetServerMetrics(options, new SocketAddressImpl(id.port, id.host)) : null; actualServer.handlerManager.addHandler(new Handlers(this, handler, exceptionHandler), listenContext);
/** * Create a domain socket address. * * @param path the address path * @return the created socket address */ static SocketAddress domainSocketAddress(String path) { return new SocketAddressImpl(path); }
/** * Create a inet socket address, {@code host} must be non {@code null} and {@code port} must be between {@code 0} * and {@code 65536}. * * @param port the address port * @param host the address host * @return the created socket address */ static SocketAddress inetSocketAddress(int port, String host) { return new SocketAddressImpl(port, host); }
public SocketAddress localAddress() { InetSocketAddress addr = (InetSocketAddress) chctx.channel().localAddress(); if (addr == null) return null; return new SocketAddressImpl(addr); }
public SocketAddress remoteAddress() { InetSocketAddress addr = (InetSocketAddress) chctx.channel().remoteAddress(); if (addr == null) return null; return new SocketAddressImpl(addr); }
@Override public SocketAddress sender() { if (senderAddress == null) { senderAddress = new SocketAddressImpl(sender.getPort(), sender.getAddress().getHostAddress()); } return senderAddress; }
@Override public SocketAddress localAddress() { InetSocketAddress addr = channel.localAddress(); return new SocketAddressImpl(addr); }
@Override public DatagramSocket listen(int port, String address, Handler<AsyncResult<DatagramSocket>> handler) { return listen(new SocketAddressImpl(port, address), handler); }
@Override @SuppressWarnings("unchecked") public DatagramSocket send(Buffer packet, int port, String host, Handler<AsyncResult<DatagramSocket>> handler) { Objects.requireNonNull(packet, "no null packet accepted"); Objects.requireNonNull(host, "no null host accepted"); if (port < 0 || port > 65535) { throw new IllegalArgumentException("port out of range:" + port); } context.owner().resolveAddress(host, res -> { if (res.succeeded()) { doSend(packet, new InetSocketAddress(res.result(), port), handler); } else { handler.handle(Future.failedFuture(res.cause())); } }); if (metrics != null) { metrics.bytesWritten(null, new SocketAddressImpl(port, host), packet.length()); } return this; }
@Test public void testSocketAddress() throws Exception { assertNullPointerException(() -> new SocketAddressImpl(0, null)); assertIllegalArgumentException(() -> new SocketAddressImpl(0, "")); assertIllegalArgumentException(() -> new SocketAddressImpl(-1, "someHost")); assertIllegalArgumentException(() -> new SocketAddressImpl(65536, "someHost")); }
VertxMetrics metrics = vertx.metricsSPI(); if (metrics != null) { this.metrics = metrics.createNetServerMetrics(options, new SocketAddressImpl(id.port, id.host)); this.actualPort = shared.actualPort(); VertxMetrics metrics = vertx.metricsSPI(); this.metrics = metrics != null ? metrics.createNetServerMetrics(options, new SocketAddressImpl(id.port, id.host)) : null; actualServer.handlerManager.addHandler(new Handlers(this, handler, exceptionHandler), listenContext);