public void startWorking(BufferedReader in, PrintWriter out) throws IOException {
        new Thread(() -> {
            try {
                String input;
                while ((input = in.readLine()) != null) {
                    lastInput = input;
                    event.run();
                }
            } catch (IOException e) {
                System.err.println("[Connection] Error pt1 : " + e);
            }

            try {
                in.close();
            } catch (IOException e) {
                System.err.println("[Connection] Error pt 2: " + e);
            }
            out.close();
            isWorking.set(false);
            if (close != null) close.run();
        }).start();


        new Thread(() -> {

                Timer t=new Timer();
                t.schedule(
                new TimerTask() {
                    public void run() {
                        sendMessages(out);
                        if (!isWorking.get())
                            this.cancel();
                    }
                }, 0, 5);

        }).start();
    }