/** Starts the local SOCKS5 proxy server. If it is already running, this method does nothing. */ public synchronized void start() { if (isRunning()) { return; } try { if (SmackConfiguration.getLocalSocks5ProxyPort() < 0) { int port = Math.abs(SmackConfiguration.getLocalSocks5ProxyPort()); for (int i = 0; i < 65535 - port; i++) { try { this.serverSocket = new ServerSocket(port + i); break; } catch (IOException e) { // port is used, try next one } } } else { this.serverSocket = new ServerSocket(SmackConfiguration.getLocalSocks5ProxyPort()); } if (this.serverSocket != null) { this.serverThread = new Thread(this.serverProcess); this.serverThread.start(); } } catch (IOException e) { // couldn't setup server System.err.println( "couldn't setup local SOCKS5 proxy on port " + SmackConfiguration.getLocalSocks5ProxyPort() + ": " + e.getMessage()); } }
/** * Returns the local SOCKS5 proxy server. * * @return the local SOCKS5 proxy server */ public static synchronized Socks5Proxy getSocks5Proxy() { if (socks5Server == null) { socks5Server = new Socks5Proxy(); } if (SmackConfiguration.isLocalSocks5ProxyEnabled()) { socks5Server.start(); } return socks5Server; }