" your version
print $socket $chat[$i], $EOL if ( $1 ne $ID && $2 ne $kill);
sends the $ID to all the Clients and there it has absolutely no meaning."

Well it's working for me. What I get echoed to all clients is the tmp ID followed by a space, followed by the client message. I find this useful, because it tells me which client originated the message. The following is how I figured it out. I just printed the chatline, and saw the needed info was in there. The chatline I get is a list, the first element is the unique client ID, and the second is the message sent. It isn't split into $1 and $2. Anyways, we both have it working the way each of us likes it best, so it really is no problem.

for my $i ( $E{$ID} .. $#chat ) { $chat[$i] =~ /(.+?)\s(.+)[\n\r]+/; print "chatline->$chat[$i]\n"; print "In writerrun \$1->$1 \$2->$2\n"; print $socket $chat[$i],$EOL; #if ( $1 ne $ID && $2 ne $ki +ll ); #what gets echoed is : Wzghb2n3 foobarfoobarfoobar

The bigger problem is the threads leaking. You observe it as the first writer not destroying itself. As I mentioned, if you don't detach $r and $w, the server crashing goes away, but there is a thread leak when you kill and restart clients. But it's a clue. I've put the detach back in, and am working on a way of "joining" the threads when they are finished. It only seems that the first thread has this problem, and maybe it has something to do with that line in the reader next if ( $NoClient < 2 ); ? It prevents the last @chat broadcast? Possible?

Sooner or later, I will find a way. I will let you know at your email address what I find. Of course, you may be successful before me, if so post it in the Snippets section. This is nice useful code, which I'm sure is sought after by many newbies. Relatives are arriving today for the holiday parties, so I may be slowed down. :-)


In reply to Re: Re: Re: thread:shared by zentara
in thread thread:shared by Anonymous Monk

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.