in reply to Sync messages for chatting peers
Your basic problem is that the my $in = <STDIN> is blocking until a complete line has been entered. So nothing else will happen in either the server or client during that time...
Maybe try reading/assembling messages on a character by character basis (non-blocking) — see Term::ReadKey. Or use separate processes or threads to handle reading the input being typed plus sending it, and printing stuff received from the other side. Generally, watch out not to create a deadlock, i.e. that both sides are waiting for the other side to make the next step (this is by no means a trivial exercise).
(At the moment, I don't have the time to compose a complete example. Maybe later... unless someone else has posted something by then. Also, it often helps to look at how existing working code does it. IOW, search CPAN — I would be surprised if no one else has written something like this already...)
|
|---|