@Override public void listen() { listenerThread = Thread.currentThread(); String threadName = listenerThread.getName(); try { while (!stop) { Socket s = serverSocket.accept(); TcpServerThread c = new TcpServerThread(s, this, nextThreadId++); running.add(c); Thread thread = new Thread(c, threadName + " thread"); thread.setDaemon(isDaemon); c.setThread(thread); thread.start(); } serverSocket = NetUtils.closeSilently(serverSocket); } catch (Exception e) { if (!stop) { DbException.traceThrowable(e); } } stopManagementDb(); }
@Override public boolean isRunning(boolean traceError) { if (serverSocket == null) { return false; } try { Socket s = NetUtils.createLoopbackSocket(port, ssl); s.close(); return true; } catch (Exception e) { if (traceError) { traceError(e); } return false; } }
@Override public void start() { stop = false; try { serverSocket = NetUtils.createServerSocket(port, false); } catch (DbException e) { if (!portIsSet) { serverSocket = NetUtils.createServerSocket(0, false); } else { throw e; } } port = serverSocket.getLocalPort(); }
/** * Create a loopback socket (a socket that is connected to localhost) on * this port. * * @param port the port * @param ssl if SSL should be used * @return the socket */ public static Socket createLoopbackSocket(int port, boolean ssl) throws IOException { String local = getLocalAddress(); try { return createSocket(local, port, ssl); } catch (IOException e) { try { return createSocket("localhost", port, ssl); } catch (IOException e2) { // throw the original exception throw e; } } }
private void startServer(String key) { try { server = Server.createTcpServer( "-tcpPort", Integer.toString(autoServerPort), "-tcpAllowOthers", "-tcpDaemon", "-key", key, databaseName); server.start(); } catch (SQLException e) { throw DbException.convert(e); } String localAddress = NetUtils.getLocalAddress(); String address = localAddress + ":" + server.getPort(); lock.setProperty("server", address); String hostName = NetUtils.getHostName(localAddress); lock.setProperty("hostName", hostName); lock.save(); }
ipAddress = NetUtils.getLocalAddress(); FileUtils.createDirectories(FileUtils.getParent(fileName)); if (!FileUtils.createFile(fileName)) { serverSocket = NetUtils.createServerSocket(0, false); int port = serverSocket.getLocalPort(); properties.setProperty("ipAddress", ipAddress);
/** * Create a client socket that is connected to the given address and port. * * @param server to connect to (including an optional port) * @param defaultPort the default port (if not specified in the server * address) * @param ssl if SSL should be used * @return the socket */ public static Socket createSocket(String server, int defaultPort, boolean ssl) throws IOException { int port = defaultPort; // IPv6: RFC 2732 format is '[a:b:c:d:e:f:g:h]' or // '[a:b:c:d:e:f:g:h]:port' // RFC 2396 format is 'a.b.c.d' or 'a.b.c.d:port' or 'hostname' or // 'hostname:port' int startIndex = server.startsWith("[") ? server.indexOf(']') : 0; int idx = server.indexOf(':', startIndex); if (idx >= 0) { port = Integer.decode(server.substring(idx + 1)); server = server.substring(0, idx); } InetAddress address = InetAddress.getByName(server); return createSocket(address, port, ssl); }
private void updateURL() { try { url = (ssl ? "https" : "http") + "://" + NetUtils.getLocalAddress() + ":" + port; } catch (NoClassDefFoundError e) { // Google App Engine does not allow java.net.InetAddress } }
/** * Create a loopback socket (a socket that is connected to localhost) on * this port. * * @param port the port * @param ssl if SSL should be used * @return the socket */ public static Socket createLoopbackSocket(int port, boolean ssl) throws IOException { InetAddress address = getBindAddress(); if (address == null) { address = InetAddress.getLocalHost(); } try { return createSocket(getHostAddress(address), port, ssl); } catch (IOException e) { try { return createSocket("localhost", port, ssl); } catch (IOException e2) { // throw the original exception throw e; } } }
boolean useLocalhost = false; try { bind = getBindAddress(); if (bind == null) { useLocalhost = true;
private boolean allow(Socket socket) { if (allowOthers) { return true; } try { return NetUtils.isLocalAddress(socket); } catch (UnknownHostException e) { traceError(e); return false; } }
boolean useLocalhost = false; try { bind = getBindAddress(); if (bind == null) { useLocalhost = true; String address = bind == null ? "localhost" : getHostAddress(bind); if (address.equals("127.0.0.1")) { address = "localhost";
/** * Create a server socket. The system property h2.bindAddress is used if * set. If SSL is used and h2.enableAnonymousTLS is true, an attempt is * made to modify the security property jdk.tls.legacyAlgorithms * (in newer JVMs) to allow anonymous TLS. * <p> * This system change is effectively permanent for the lifetime of the JVM. * @see CipherFactory#removeAnonFromLegacyAlgorithms() * * @param port the port to listen on * @param ssl if SSL should be used * @return the server socket */ public static ServerSocket createServerSocket(int port, boolean ssl) { try { return createServerSocketTry(port, ssl); } catch (Exception e) { // try again return createServerSocketTry(port, ssl); } }
public static Socket createLoopbackSocket(int port, boolean ssl) throws IOException { InetAddress address = getBindAddress(); if (address == null) { address = InetAddress.getLocalHost(); } return createSocket(address.getHostAddress(), port, ssl); }
/** * Open a new new connection to the same address and port as this one. * * @return the new transfer object */ public Transfer openNewConnection() throws IOException { InetAddress address = socket.getInetAddress(); int port = socket.getPort(); Socket s2 = NetUtils.createSocket(address, port, ssl); Transfer trans = new Transfer(null, s2); trans.setSSL(ssl); return trans; }
@Override public String getURL() { return "pg://" + NetUtils.getLocalAddress() + ":" + port; }
/** * Create a loopback socket (a socket that is connected to localhost) on * this port. * * @param port the port * @param ssl if SSL should be used * @return the socket */ public static Socket createLoopbackSocket(int port, boolean ssl) throws IOException { InetAddress address = getBindAddress(); if (address == null) { address = InetAddress.getLocalHost(); } try { return createSocket(getHostAddress(address), port, ssl); } catch (IOException e) { try { return createSocket("localhost", port, ssl); } catch (IOException e2) { // throw the original exception throw e; } } }
ipAddress = NetUtils.getLocalAddress(); FileUtils.createDirectories(FileUtils.getParent(fileName)); if (!FileUtils.createFile(fileName)) { serverSocket = NetUtils.createServerSocket(0, false); int port = serverSocket.getLocalPort(); properties.setProperty("ipAddress", ipAddress);
private void startServer(String key) { try { server = Server.createTcpServer( "-tcpPort", Integer.toString(autoServerPort), "-tcpAllowOthers", "-tcpDaemon", "-key", key, databaseName); server.start(); } catch (SQLException e) { throw DbException.convert(e); } String localAddress = NetUtils.getLocalAddress(); String address = localAddress + ":" + server.getPort(); lock.setProperty("server", address); String hostName = NetUtils.getHostName(localAddress); lock.setProperty("hostName", hostName); lock.save(); }
private static ServerSocket createServerSocketTry(int port, boolean ssl) { try { InetAddress bindAddress = getBindAddress(); if (ssl) { return CipherFactory.createServerSocket(port, bindAddress); } if (bindAddress == null) { return new ServerSocket(port); } return new ServerSocket(port, 0, bindAddress); } catch (BindException be) { throw DbException.get(ErrorCode.EXCEPTION_OPENING_PORT_2, be, "" + port, be.toString()); } catch (IOException e) { throw DbException.convertIOException(e, "port: " + port + " ssl: " + ssl); } }