public void run(){
            try{
                while(serverOn){
                    System.out.println("Waiting for changes");

                    ObjectInputStream in = new ObjectInputStream(socket.getInputStream());

                    try {
                        String type = (String) in.readObject();
                        Object changedObject = in.readObject();

                        dataHandler.editDatabase(changedObject, type);
                        dataHandler.receiveChanges(changedObject, type);
                        sendChanges(changedObject, type);
                    }catch(ClassNotFoundException e){
                        System.out.println("Received unapproved item");
                    }
                }
            }catch(IOException e){
                System.out.println("Disconnected from " + socket);
            }finally{
                try{
                    clients.remove(socket);
                    socket.close();
                }catch(Exception e){
                    e.printStackTrace();
                }
            }
        }