i made a client server echo program but it doesn't work, here is the client         try{
            SocketAddress address = new InetSocketAddress(port);
            SocketChannel client = SocketChannel.open(address);
            client.configureBlocking(false);
            
            Scanner scanner = new Scanner(System.in);
            System.out.println("Inserisci messaggio da inviare \n");
            String input = scanner.nextLine();
            ByteBuffer buffer = ByteBuffer.wrap(input.getBytes());
            client.write(buffer);
            ByteBuffer readBuffer= ByteBuffer.allocate(1024);
            int numBytesRead = client.read(readBuffer);
            readBuffer.flip();
            System.out.println("letti "+numBytesRead);
            byte[] bytes = new byte[readBuffer.remaining()];
            readBuffer.get(bytes);
            System.out.println("Received message from server: " + new String(bytes));

        } catch(IOException e){
            e.printStackTrace();
        } and here is the server snippet while (true) {
                selector.select();
                Set<SelectionKey> readyKeys = selector.selectedKeys();
                Iterator<SelectionKey> iterator = readyKeys.iterator();

                while (iterator.hasNext()) {
                    SelectionKey key = iterator.next();
                    iterator.remove();

                    try {
                        if (key.isAcceptable()) {
                            ServerSocketChannel server = (ServerSocketChannel) key.channel();
                            SocketChannel client = server.accept();
                            System.out.println("Accepted connection from " + client);
                            client.configureBlocking(false);
                            client.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);
                            dataMap.put(client, new ArrayList<>());
                        } else if (key.isReadable()) {
                            SocketChannel client = (SocketChannel) key.channel();
                            ByteBuffer buffer = ByteBuffer.allocate(1024);
                            int bytesRead = client.read(buffer);

                            if (bytesRead == -1) {
                                // Client disconnected
                                System.out.println("chiuso\n");
                                key.cancel();
                                client.close();
                                dataMap.remove(client);
                            } else if (bytesRead > 0) {
                                buffer.flip();
                                byte[] bytes = new byte[buffer.remaining()];
                                buffer.get(bytes);
                                System.out.println("Received message from " + client + ": " + new String(bytes));
                                buffer.flip();
                                System.out.println("size"+buffer.remaining());
                                System.out.println("size"+buffer.remaining());
                                client.write(buffer);

                                // You can process the received message here
                            }
                        }
                    } catch (IOException ex) {
                        key.cancel();
                        try {
                            key.channel().close();
                        } catch (IOException cex) {
                        }
                    } why does the client always receives 0 bytes back?