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...)


In reply to Re: Sync messages for chatting peers by almut
in thread Sync messages for chatting peers by kzle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.