I just see that you've gotten an answer in the CB (add my() to the while() loop), but here's a better version of the scipt. Yes, I skip the wait() for waiting on the children. If you add it, the server will quit after the first client disconnects. :) What can I say? I like zombies :P
#!/usr/bin/perl -w $|++; use strict; use IO::Socket; my $main_sock = new IO::Socket::INET( LocalHost => '24.71.183.153', LocalPort => 7800, Listen => 1, Proto => 'tcp', Reuse => 1 ) or die "Oops: $!"; while (my $new_sock = $main_sock->accept()) { if (my $pid = fork()) { # Parent next; } elsif (defined $pid) { # Child print $new_sock 'Hello there, it is now ', localtime, "\n"; while (defined( chomp( my $buf = <$new_sock> ) ) ) { print "Client said: $buf\n"; if ($buf =~ /^quit/) { close $new_sock; last; } } } else { die "Cannot fork: $!" unless defined($pid); } exit(0); } exit(0);
If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, reply to this node or /msg me to tell me what is wrong with the post, so that I may update the node to the best of my ability. If you do not inform me as to why the post deserved a downvote, your vote does not have any significance and will be disregarded.
In reply to Re: Close Socket Force client to quit.
by Coruscate
in thread Close Socket Force client to quit.
by PyroX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |