in reply to IO::Sockets server

I'd use Net::Server.
package Foo; use base qw(Net::Server); open(my $log, '>>', 'log.txt') || die "Couldn't open log.txt: $!"; Foo->run(port => 7777); sub process_request { while (<STDIN>) { print "You said: $_"; print $log "They said: $_"; } }


There are many many options available including Fork, PreFork, Multiplex, and others. See the perldoc for Net::Server.

my @a=qw(random brilliant braindead); print $a[rand(@a)];

Replies are listed 'Best First'.
Re^2: IO::Sockets server
by xarex (Initiate) on May 17, 2007 at 15:34 UTC
    Thanks guys, I have the following and its working great:
    #!/usr/bin/perl -w my $socket; my $port = 7777; my $host; use IO::Socket; use Sys::Hostname; $SIG{CHLD} = sub {wait ()}; $host = hostname(); # START LOOP HERE my $main_sock = new IO::Socket::INET (LocalHost => $host, LocalPort => $port, Listen => 5, Proto => 'tcp', Reuse => 1, ); if (!$main_sock) { die "Socket could not be created. Reason: $!\n"; } my $buf; my $new_sock; my $pid; while ($new_sock = $main_sock->accept()) { $pid = fork(); if ($pid == 0) { # Child process while (defined ($buf = <$new_sock>)) { # do something with $buf .... my @lines = split(/\|/,$buf); exit(0); # Child process exits when it is done. } } # else 'tis the parent process, which goes back to accept() } close ($main_sock); exit; However how do i save the data recieved to a log file? say /usr/home/l +og.txt