    public void run() {
        try {
        	System.out.println("In thread for connect to network");
            distConf = DistConfig.get_Instance();
            BufferedReader inStream = new BufferedReader (
                    new InputStreamReader(client.getInputStream()));
            System.out.println("Got input stream");
            BufferedOutputStream bos = new BufferedOutputStream (
                    client.getOutputStream());
            PrintWriter outStream = new PrintWriter(bos, false);
            System.out.println("Got out stream");
            ObjectOutputStream oos = new ObjectOutputStream (bos);
            System.out.println("Got object output stream");
            System.out.println("Sending the dist config");
            oos.writeObject(distConf);
            System.out.println("Sending user management");
            oos.writeObject(UserManagement.get_Instance());
            oos.flush();
            System.out.println("Receiving reply");
            inStream.readLine();
            NodeSearchTable distConnTable = 
                    NodeSearchTable.get_Instance();
            InetAddress cliAddress = client.getInetAddress();
            int newClientID = 
                    Sha1Generator.generate_Sha1(cliAddress.getHostAddress());
            System.out.println("Sha1 is " + Integer.toString(newClientID));
            if (distConf.get_UseGlobalNodeTable()) {
                GlobalNodeTable dgt = GlobalNodeTable.get_instance();
                while (dgt.contains_ID(newClientID)) {
                    newClientID = (newClientID + 1) % distConf.get_MaxNodes();
                }
            }
            else {
                while (distConnTable.contains_ID(newClientID)) {
                    newClientID = (newClientID + 1) % distConf.get_MaxNodes();
                }
            }
            outStream.println(Integer.toString(newClientID));
            outStream.flush();
            inStream.readLine();
            if (distConf.get_UseGlobalNodeTable()) {
                GlobalNodeTable dgt = GlobalNodeTable.get_instance();
                oos.writeObject(dgt);
                oos.flush();
            }
            else if (distConnTable.size() == 0) {
                outStream.println(distConnTable.get_ownID());
                outStream.println(distConnTable.get_ownIPAddress());
                outStream.flush();
            }
            else {
                String ipAddress = distConnTable.get_ownIPAddress();
                int id = Integer.parseInt(distConnTable.get_ownID());
                boolean found = false;
                for (int index = 0; index < distConnTable.size(); index++) {
                    int nextID = Integer.parseInt(distConnTable.get_IDAt(index));
                    if (newClientID >= id && newClientID < nextID) {
                        found = true;
                    }
                    else if (newClientID >= id && newClientID > nextID) {
                        found = true;
                    }
                    else if (newClientID <= id && newClientID < nextID) {
                        found = true;
                    }
                    if (!found) {
                        id = nextID;
                        ipAddress = distConnTable.get_IPAt(index);
                    }
                }
                outStream.println(Integer.toString(id));
                outStream.println(ipAddress);
                outStream.flush();
            }
            inStream.readLine();
            inStream.close();
            oos.close();
            outStream.close();
            bos.close();
            client.close();
        } catch (IOException ex) {
            try {
                client.close();
            } catch (IOException ex1) {
                Logger.getLogger(ServEnterNetwork.class.getName()).log(Level.SEVERE, null, ex1);
            }
            Logger.getLogger(ServEnterNetwork.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void run() {
        try {
        	System.out.println("In thread for connect to network");
            distConf = DistConfig.get_Instance();
            BufferedReader inStream = new BufferedReader (
                    new InputStreamReader(client.getInputStream()));
            System.out.println("Got input stream");
            BufferedOutputStream bos = new BufferedOutputStream (
                    client.getOutputStream());
            PrintWriter outStream = new PrintWriter(bos, false);
            System.out.println("Got out stream");
            ObjectOutputStream oos = new ObjectOutputStream (bos);
            System.out.println("Got object output stream");
            System.out.println("Sending the dist config");
            oos.writeObject(distConf);
            oos.flush();
            System.out.println("Sending user management");
            oos.writeObject(UserManagement.get_Instance());
            oos.flush();
            System.out.println("Receiving reply");
            inStream.readLine();
            NodeSearchTable distConnTable = 
                    NodeSearchTable.get_Instance();
            InetAddress cliAddress = client.getInetAddress();
            int newClientID = 
                    Sha1Generator.generate_Sha1(cliAddress.getHostAddress());
            System.out.println("Sha1 is " + Integer.toString(newClientID));
            if (distConf.get_UseGlobalNodeTable()) {
                GlobalNodeTable dgt = GlobalNodeTable.get_instance();
                while (dgt.contains_ID(newClientID)) {
                    newClientID = (newClientID + 1) % distConf.get_MaxNodes();
                }
            }
            else {
                while (distConnTable.contains_ID(newClientID)) {
                    newClientID = (newClientID + 1) % distConf.get_MaxNodes();
                }
            }
            outStream.println(Integer.toString(newClientID));
            outStream.flush();
            inStream.readLine();
            if (distConf.get_UseGlobalNodeTable()) {
                GlobalNodeTable dgt = GlobalNodeTable.get_instance();
                oos.writeObject(dgt);
                oos.flush();
            }
            else if (distConnTable.size() == 0) {
                outStream.println(distConnTable.get_ownID());
                outStream.println(distConnTable.get_ownIPAddress());
                outStream.flush();
            }
            else {
                String ipAddress = distConnTable.get_ownIPAddress();
                int id = Integer.parseInt(distConnTable.get_ownID());
                boolean found = false;
                for (int index = 0; index < distConnTable.size(); index++) {
                    int nextID = Integer.parseInt(distConnTable.get_IDAt(index));
                    if (newClientID >= id && newClientID < nextID) {
                        found = true;
                    }
                    else if (newClientID >= id && newClientID > nextID) {
                        found = true;
                    }
                    else if (newClientID <= id && newClientID < nextID) {
                        found = true;
                    }
                    if (!found) {
                        id = nextID;
                        ipAddress = distConnTable.get_IPAt(index);
                    }
                }
                outStream.println(Integer.toString(id));
                outStream.println(ipAddress);
                outStream.flush();
            }
            inStream.readLine();
            inStream.close();
            oos.close();
            outStream.close();
            bos.close();
            client.close();
        } catch (IOException ex) {
            try {
                client.close();
            } catch (IOException ex1) {
                Logger.getLogger(ServEnterNetwork.class.getName()).log(Level.SEVERE, null, ex1);
            }
            Logger.getLogger(ServEnterNetwork.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
