log.error("Failed to start the router " + "on port " + routerPort);
System.err.println("Failed to start the router " + "on port " + routerPort);
    private int startRouter() throws Exception {        final int routerPort=getFreePort();        Thread routerThread=new Thread(new Runnable() {            public void run() {                try {                    new GossipRouter(routerPort).start();                    System.out.println("started GossipRouter on port " + routerPort);                }                catch(Exception e) {                    log.error("Failed to start the router " + "on port " + routerPort);                    e.printStackTrace();                }            }        });        routerThread.start();        // verify the router - try to connect for 10 secs        long startms=System.currentTimeMillis();        long crtms=startms;        Exception lastConnectException=null;        while(crtms - startms < 10000) {            Socket s=null;            try {                s=new Socket("localhost", routerPort);            }            catch(Exception e) {                lastConnectException=e;                Thread.sleep(1000);                crtms=System.currentTimeMillis();                continue;            }            lastConnectException=null;            DataInputStream dis=new DataInputStream(s.getInputStream());            DataOutputStream dos=new DataOutputStream(s.getOutputStream());            // read the IpAddress            int len=dis.readInt();            byte[] buffer=new byte[len];            dis.read(buffer, 0, len);            // write a GET            dos.writeInt(Router.GET);            dos.writeUTF("nogroup_setup");            dis.readInt();            s.close();            break;        }        if(lastConnectException != null) {            lastConnectException.printStackTrace();            fail("Cannot connect to the router");        }        System.out.println("router ok");        return routerPort;    }