/** Destroy the server */ public void destroy() { closeAllSockets(); if (serverSocket != null) { try { serverSocket.close(); } catch (IOException e) { Util.printStackTrace(e); } serverSocket = null; } }
/** * Create a new ContextServer using the ThreadPool. * * @param threadPool Obtain runnables from this pool. If null, new threads will be created. */ public SocketContextServer(AppThreadPool threadPool, boolean promiscuous, String contextName) { this.threadPool = threadPool; this.contextName = contextName; try { serverSocket = JavaBridge.bind(promiscuous ? "INET:0" : "INET_LOCAL:0"); SecurityManager sec = System.getSecurityManager(); if (sec != null) sec.checkAccept("127.0.0.1", Integer.parseInt(serverSocket.getSocketName())); Thread t = new Util.Thread( this, "JavaBridgeSocketContextServer(" + serverSocket.getSocketName() + ")"); t.start(); } catch (Throwable t) { Util.warn("Local communication channel not available."); Util.printStackTrace(t); if (serverSocket != null) try { serverSocket.close(); } catch (IOException e) { } serverSocket = null; } }