@Override
    public void run(){
        System.out.println("Session started");

        try{
            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
            ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
            while (true){
                Object request = ois.readObject();
                if (request instanceof LsRequest){
                    LsRequest lsRequest = (LsRequest) request;
                    String dir = lsRequest.getDir();
                    File[] files;
                    if (dir == null || dir.length() == 0){
                        files = config.getBaseDIr().listFiles();
                    } else {
                        files = new File(config.getBaseDIr(), dir).listFiles();
                    }

                    List<String> fileNames = new ArrayList<String>();
                    for (File f: files){
                        fileNames.add(f.getName());
                    }
                    LsResponse response = new LsResponse();
                    response.setFiles(fileNames);
                    oos.writeObject(response);
                } else if (request instanceof FileRequest){
                    FileRequest fr = (FileRequest) request;
                    File file = new File(config.getBaseDIr(), fr.getFile());
                    FileInputStream fis = new FileInputStream(file);
                    long fileLenght = file.length();
                    byte [] buffer = new byte[(int) fileLenght];
                    int idx = 0;
                    while (true){
                        int b = fis.read();
                        if (b == -1){
                            break;
                        }
                        buffer[idx++] = (byte) b;
                    }
                    FileResponse fileResponse = new FileResponse();
                    fileResponse.setFileContent(buffer);
                            oos.writeObject(fileResponse);

                }
                oos.flush();
                oos.reset();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println("Session terminated");
    }