// {{{ EditServer constructor EditServer(String portFile) { super("jEdit server daemon [" + portFile + "]"); setDaemon(true); this.portFile = portFile; try { // On Unix, set permissions of port file to rw-------, // so that on broken Unices which give everyone read // access to user home dirs, people can't see your // port file (and hence send arbitriary BeanShell code // your way. Nasty.) if (OperatingSystem.isUnix()) { new File(portFile).createNewFile(); FileVFS.setPermissions(portFile, 0600); } // Bind to any port on localhost; accept 2 simultaneous // connection attempts before rejecting connections socket = new ServerSocket(0, 2, InetAddress.getByName("127.0.0.1")); authKey = new Random().nextInt(Integer.MAX_VALUE); int port = socket.getLocalPort(); FileWriter out = new FileWriter(portFile); try { out.write("b\n"); out.write(String.valueOf(port)); out.write("\n"); out.write(String.valueOf(authKey)); out.write("\n"); } finally { out.close(); } ok = true; Log.log(Log.DEBUG, this, "jEdit server started on port " + socket.getLocalPort()); Log.log(Log.DEBUG, this, "Authorization key is " + authKey); } catch (IOException io) { /* on some Windows versions, connections to localhost * fail if the network is not running. To avoid * confusing newbies with weird error messages, log * errors that occur while starting the server * as NOTICE, not ERROR */ Log.log(Log.NOTICE, this, io); } } // }}}