#!/usr/bin/perl -w use IO::Socket; use strict; $SIG{CHLD} = sub{ wait; }; my $inputLine; my $new_sock; my $main_sock; my $pid; # Create Socket on port 7070 $main_sock = new IO::Socket::INET ( LocalHost => 'localhost', LocalPort => '7070', Proto => 'tcp', Listen => 1, Reuse => 1, ); die "Could not create socket: $!\n" unless $main_sock; print "Telnet Server listening on 7070....\n"; # Accept connection and fork child! while( $new_sock = $main_sock->accept() ){ $pid = fork(); unless( defined($pid) ){ die "Cannot fork\n"; } ################## # CHILD PROCESS ################## if($pid == 0) { # Print Welcome message! welcomeClient($new_sock); while( defined( $inputLine=<$new_sock>) ) { $inputLine =~ s/[\r\n]//g; if( $inputLine eq "printhelp" ){ callPrintHelp($new_sock); }elsif( $inputLine eq "quit" ){ callQuit($new_sock); exit(0); }else{ print $new_sock "INFO> Not implemented yet\n"; } }#while exit(0); } ################## # CHILD PROCESS ################## }# while main_sock close($main_sock); sub welcomeClient { # Show starting point for client and help messages my ($client_sock) = @_; print $client_sock "######################################\n"; print $client_sock " Telnet Interface \n"; print $client_sock "######################################\n\n"; print $client_sock "INFO> Type 'printhelp' for help\n\n"; print $client_sock "READY:\n"; print $client_sock ">"; } sub callPrintHelp{ my ($client_sock) = @_; ...... ..... } sub callQuit{ my ($client_sock) = @_; ...... ..... }