does any of you have experience with this?
I'm attaching the script, it's short and after running it you can telnet to localhost:8081
Code:
use IO::Socket; use Term::ReadLine; ##################################### # Server Script: # Copyright 2003 (c) Philip Yuson # this program is distributed according to # the terms of the Perl license # Use at your own risk #####################################
$local = IO::Socket::INET->new(
Proto => 'tcp', # protocol
LocalAddr => 'localhost:8081', # Host and port to listen to
# Change the port if 8081 is being used
Reuse => 1
) or die "$!";
##################################### # Server Script: # Copyright 2003 (c) Philip Yuson # this program is distributed according to # the terms of the Perl license # Use at your own risk #####################################
$local = IO::Socket::INET->new(
Proto => 'tcp', # protocol
LocalAddr => 'localhost:8081', # Host and port to listen to
# Change the port if 8081 is being used
Reuse => 1
) or die "$!";
$local->listen(); # listen $local->autoflush(1); # To send response immediately
print "At your service. Waiting...\n"; my $addr; # Client handle while ($addr = $local->accept() ) { # receive a request print "Connected from: ", $addr->peerhost(); # Display messages print " Port: ", $addr->peerport(), "\n";
my $result; # variable for Result #while (<$addr>) { # Read all messages from client ## (Assume all valid numbers) #last if m/^end/gi; # if message is 'end' ## then exit loop #print "Received: $_"; # Print received message #print $addr $_; # Send received message back ## to verify #$result += $_; # Add value to result #} $term = new Term::ReadLine('Simple Perl calc'); $prompt = "Enter your arithmetic expression: "; #$OUT = $term->OUT || STDOUT;
while ( defined ($_ = $term->readline($prompt)) ) { $res = eval($_), "\n"; warn $@ if $@; print $OUT $res, "\n" unless $@; $term->addhistory($_) if /\S/; }
chomp; # Remove the <CR>
if (m/^end/gi) { # You need this. Otherwise if
# the client terminates abruptly
# The server will encounter an
# error when it sends the result back
# and terminate
my $send = "result=$result"; # Format result message
print $addr "$send\n"; # send the result message
print "Result: $send\n"; # Display sent message
}
print "Closed connection\n"; # Inform that connection
# to client is closed
close $addr; # close client
print "At your service. Waiting...\n"; # Wait again for next request
}
-- Ernest Beinrohr, OERNii eAdmin @ axonpro.sk, http://www.axonpro.sk/ +421-2--6241-0360, +421-903--482-603 HomePage: http://www.OERNii.sk/ ICQ: 28153343 --- There are 10 kinds of people, those that understand binary, and those that do not
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>