public InetAddress getBindAddress() { return socket.getInetAddress(); }
public InetAddress getServerInetAddr() { return this.serverSock.getInetAddress(); }
/** This method will close the socket upon first initialization. */ protected InetSocketAddress getWebAddressFromBindSocket() throws IOException { Preconditions.checkNotNull(mWebBindSocket, "mWebBindSocket"); InetSocketAddress socketAddr = new InetSocketAddress(mWebBindSocket.getInetAddress(), mWebBindSocket.getLocalPort()); mWebBindSocket.close(); return socketAddr; }
/** * Gets the local socket address of this server socket or {@code null} if * the socket is unbound. This is useful on multihomed hosts. * * @return the local socket address and port this socket is bound to. */ public SocketAddress getLocalSocketAddress() { if (!isBound()) { return null; } return new InetSocketAddress(getInetAddress(), getLocalPort()); }
public void run() { LOG.info("starting "+channel.socket().getInetAddress()); try { while (true) { try { new Connection(channel.accept()); } catch (ClosedChannelException e) { return; } catch (IOException e) { LOG.warn("unexpected error", e); throw new RuntimeException(e); } } } finally { LOG.info("stopping "+channel.socket().getInetAddress()); try { channel.close(); } catch (IOException e) { } } }
/** * Returns a textual representation of this server socket including the * address, port and the state. The port field is set to {@code 0} if there * is no connection to the server socket. * * @return the textual socket representation. */ @Override public String toString() { StringBuilder result = new StringBuilder(64); result.append("ServerSocket["); if (!isBound()) { return result.append("unbound]").toString(); } return result.append("addr=") .append(getInetAddress().getHostName()).append("/") .append(getInetAddress().getHostAddress()).append( ",port=0,localport=") .append(getLocalPort()).append("]") .toString(); }
/** * @param socket * @param bindAddress * @return real hostName * @throws UnknownHostException */ protected String resolveHostName(ServerSocket socket, InetAddress bindAddress) throws UnknownHostException { String result = null; if (socket.isBound()) { if (socket.getInetAddress().isAnyLocalAddress()) { // make it more human readable and useful, an alternative to 0.0.0.0 result = InetAddressUtil.getLocalHostName(); } else { result = socket.getInetAddress().getCanonicalHostName(); } } else { result = bindAddress.getCanonicalHostName(); } return result; }
protected void stopServing() throws Exception { if (isServing()) { LOG.info("Stopping RPC server on {} @ {}", this, mRpcBindSocket.getInetAddress()); if (!mGrpcServer.shutdown()) { LOG.warn("RPC Server shutdown timed out."); } } if (mWebServer != null) { mWebServer.stop(); mWebServer = null; } }
@Override public ServerSocket createServerSocket(int port) throws IOException { ServerSocket sock = null; if ("".equals(bindAddress)) { sock = socketCreator.createServerSocket(port, this.backlog); } else { sock = socketCreator.createServerSocket(port, this.backlog, InetAddressUtil.toInetAddress(this.bindAddress)); } if (logger.isDebugEnabled()) { logger.debug( "MX4JServerSocketFactory RMIServerSocketFactory, INetAddress {}, LocalPort {}, LocalSocketAddress {}", sock.getInetAddress(), sock.getLocalPort(), sock.getLocalSocketAddress()); } return sock; }
private ExecutorService initializeHandshakerThreadPool() throws IOException { String threadName = "Handshaker " + serverSock.getInetAddress() + ":" + this.localPort + " Thread "; try { logger.warn("Handshaker max Pool size: " + HANDSHAKE_POOL_SIZE); return LoggingExecutors.newThreadPoolWithSynchronousFeedThatHandlesRejection(threadName, thread -> getStats().incAcceptThreadsCreated(), null, 1, HANDSHAKE_POOL_SIZE, 60); } catch (IllegalArgumentException poolInitException) { this.stats.close(); this.serverSock.close(); this.pool.shutdown(); throw poolInitException; } }
/** * binds the server socket and gets threads going */ private void startAcceptor() throws ConnectionException { int localPort; int p = this.port; createServerSocket(); try { localPort = socket.getLocalPort(); id = new InetSocketAddress(socket.getInetAddress(), localPort); stopped = false; thread = new LoggingThread("P2P Listener Thread " + id, this); try { thread.setPriority(Thread.MAX_PRIORITY); } catch (Exception e) { logger.info("unable to set listener priority: {}", e.getMessage()); } if (!Boolean.getBoolean("p2p.test.inhibitAcceptor")) { thread.start(); } else { logger.fatal( "p2p.test.inhibitAcceptor was found to be set, inhibiting incoming tcp/ip connections"); socket.close(); } } catch (IOException io) { String s = "While creating ServerSocket on port " + p; throw new ConnectionException(s, io); } this.port = localPort; }
private void initializeServerSocket() throws IOException { if (srv_sock == null || srv_sock.isClosed()) { if (bind_address == null) { srv_sock = getSocketCreator().createServerSocket(port, BACKLOG); bind_address = srv_sock.getInetAddress(); } else { srv_sock = getSocketCreator().createServerSocket(port, BACKLOG, bind_address); } // GEODE-4176 - set the port from a wild-card bind so that handlers know the correct value if (this.port <= 0) { this.port = srv_sock.getLocalPort(); } if (log.isInfoEnabled()) { log.info("Locator was created at " + new Date()); log.info("Listening on port " + getPort() + " bound on address " + bind_address); } srv_sock.setReuseAddress(true); } }
/** * Initialize fields used in the tests. * * @throws Exception should not happen */ @Before public void setup() throws Exception { // create SOCKS5 proxy server socket serverSocket = NetworkUtil.getSocketOnLoopback(); serverAddress = serverSocket.getInetAddress().getHostAddress(); serverPort = serverSocket.getLocalPort(); }
peer.start(); Socket socket = new Socket(serverSocket.getInetAddress(), serverSocket.getLocalPort()); socket.setReceiveBufferSize(SOCKET_BUFFER_SIZE); socket.setSendBufferSize(SOCKET_BUFFER_SIZE);
new LoggingThread("Cache Server Acceptor " + this.serverSock.getInetAddress() + ":" + this.localPort + " local port: " + this.serverSock.getLocalPort(), false, this); this.acceptorId = thread.getId(); new LoggingThread("Cache Server Selector " + this.serverSock.getInetAddress() + ":" + this.localPort + " local port: " + this.serverSock.getLocalPort(), false,
@Override public void run() { String hostAddress = serverSocket.getInetAddress().getHostAddress(); int port = serverSocket.getLocalPort(); logger.log("Listening on %s:%d", hostAddress, port);
@Override public void run() { String hostAddress = serverSocket.getInetAddress().getHostAddress(); int port = serverSocket.getLocalPort(); logger.log("Listening on %s:%d", hostAddress, port);
@Override public void run() { String hostAddress = serverSocket.getInetAddress().getHostAddress(); int port = serverSocket.getLocalPort(); logger.log("Listening on %s:%d", hostAddress, port);
ListenSocketAddress unContestedAddress = new ListenSocketAddress( httpsSocket.getInetAddress().getHostName(), 0 ); ListenSocketAddress httpsAddress = new ListenSocketAddress( httpsSocket.getInetAddress().getHostName(), httpsSocket.getLocalPort() ); AssertableLogProvider logProvider = new AssertableLogProvider(); CommunityNeoServer server = CommunityServerBuilder.server( logProvider )
@Test public void shouldComplainIfServerPortIsAlreadyTaken() throws IOException { try ( ServerSocket socket = new ServerSocket( 0, 0, InetAddress.getLocalHost() ) ) { ListenSocketAddress contestedAddress = new ListenSocketAddress( socket.getInetAddress().getHostName(), socket.getLocalPort() ); AssertableLogProvider logProvider = new AssertableLogProvider(); CommunityNeoServer server = CommunityServerBuilder.server( logProvider ) .onAddress( contestedAddress ) .usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() ) .build(); try { server.start(); fail( "Should have reported failure to start" ); } catch ( ServerStartupException e ) { assertThat( e.getMessage(), containsString( "Starting Neo4j failed" ) ); } logProvider.assertAtLeastOnce( AssertableLogProvider.inLog( containsString( "CommunityNeoServer" ) ).error( "Failed to start Neo4j on %s: %s", contestedAddress, format( "Address %s is already in use, cannot bind to it.", contestedAddress ) ) ); server.stop(); } }