List of usage examples for io.vertx.core.net NetSocket remoteAddress
@CacheReturn SocketAddress remoteAddress();
From source file:io.servicecomb.foundation.vertx.server.TcpServerConnection.java
License:Apache License
public void init(NetSocket netSocket) { // currently, socket always be NetSocketImpl this.initNetSocket((NetSocketImpl) netSocket); String remoteAddress = netSocket.remoteAddress().toString(); LOGGER.info("connect from {}, in thread {}", remoteAddress, Thread.currentThread().getName()); netSocket.exceptionHandler(e -> { LOGGER.error("disconected from {}, in thread {}, cause {}", remoteAddress, Thread.currentThread().getName(), e.getMessage()); });// w w w. j a v a 2s .com netSocket.closeHandler(Void -> { LOGGER.error("disconected from {}, in thread {}", remoteAddress, Thread.currentThread().getName()); }); netSocket.handler(splitter); }
From source file:org.apache.servicecomb.foundation.vertx.server.TcpServerConnection.java
License:Apache License
public void init(NetSocket netSocket, AtomicInteger connectedCounter) { // currently, socket always be NetSocketImpl this.initNetSocket((NetSocketImpl) netSocket); String remoteAddress = netSocket.remoteAddress().toString(); LOGGER.info("connect from {}, in thread {}", remoteAddress, Thread.currentThread().getName()); netSocket.exceptionHandler(e -> { LOGGER.error("disconected from {}, in thread {}, cause {}", remoteAddress, Thread.currentThread().getName(), e.getMessage()); });/*from w ww . java 2 s . c o m*/ netSocket.closeHandler(Void -> { LOGGER.error("disconected from {}, in thread {}", remoteAddress, Thread.currentThread().getName()); int connectedCount = connectedCounter.decrementAndGet(); EventManager.post( new ClientEvent(remoteAddress, ConnectionEvent.Closed, TransportType.Highway, connectedCount)); }); netSocket.handler(splitter); }
From source file:org.lealone.server.TcpServer.java
License:Open Source License
/** * Check if this socket may connect to this server. * Remote connections are allowed if the flag allowOthers is set. * * @param socket the socket//from w w w .j ava 2s. co m * @return true if this client may connect */ private boolean allow(NetSocket socket) { if (allowOthers) { return true; } try { String test = socket.remoteAddress().host(); InetAddress localhost = InetAddress.getLocalHost(); // localhost.getCanonicalHostName() is very very slow String host = localhost.getHostAddress(); if (test.equals(host)) { return true; } for (InetAddress addr : InetAddress.getAllByName(host)) { if (test.equals(addr)) { return true; } } return false; } catch (UnknownHostException e) { return false; } }