I haven't used this exact module. I am curious about this: $chan->blocking(1) ; You want a non-blocking read that returns immediately if no data is available to be read. Maybe this flag is wrong? Update: I'll need to study this a bit more - it been a while since I've done such things. You may also need some kind of a flush to get the write to happen. I think this is more involved than my first impression.
I managed to fix the problem. As I pondered it over dinner, I thought about the mysterious send_eof() and it did the trick: now the program works just fine. A $chan->send_eof() and it all seems to work..