@Override
    public void run() {

        System.out.println("Summary:\n");
        System.out.println(fs.printSummary());



        while (running) {


            try {


                FishPacket fp = (FishPacket) in.readObject();
                System.out.println("FishPacket recived!" + fp.getHeader().getType());
                if (fp.getHeader().getType() == PacketType.ADDFILE) {
                    FileList fl = (FileList) fp.getPayload();
                    ArrayList<FishFile> listOfFishFilesToAdd = getListOfFishFilesToAdd(client,fl);
                    ArrayList<FishFile> listOfFishFilesToRemove = getListOfFishFilesToRemove(client,fl);


                    fs.updateFilesOfClient(listOfFishFilesToAdd, listOfFishFilesToRemove, client);
                } else if (fp.getHeader().getType() == PacketType.SEARCH) {

                    ParameterToSearch par = (ParameterToSearch) fp.getPayload();
                    System.out.println(fp.getPayload().printSummary());
                    FishPacket search = fs.search(client, par.getParameter());
                    sendResult(search);

                } else if (fp.getHeader().getType() == PacketType.STATISTICS) {
                    ServerStatistics sts = (ServerStatistics) fp.getPayload();
                    FishPacket result = fs.getStatistics(client);
                    sendResult(result);
                } else if (fp.getHeader().getType() == PacketType.LISTENINGSERVERPORT) {

                    ListeningServerPortNumber pn = (ListeningServerPortNumber) fp.getPayload();
                    System.out.println("Received: " + pn.printSummary());
                    Integer port = pn.port;
                    client.setListeningServerPort(port);
                }

            } catch (IOException ex) {

                running = false;
                System.out.println("Client " + client.getNetResources().getSocket().getInetAddress() + "disconnected");
                fs.clientDisconnected(client);


            } catch (ClassNotFoundException ex) {
                Logger.getLogger(ConnectionHandler.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
        //client disconnects
        try {
            closeConnection();
        } catch (IOException e) {
            System.out.println("Error while closing the connection");
            e.printStackTrace();
        }

    }