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