Another option is Net::Server (my specific example will use the Net::Server::PreForkSimple personality. This script will prefork 5 servers and therefore allow up to 5 users to interact with the server simultaneously. Throw in a database and it's actually quite simple to have the clients interact as well. (ie: One user does something, everyone sees what happened). To my knowledge and/or ability, you have to use a storage method (ie: mysql database) to get output to all clients. I got carried away and threw in a couple special escape sequences :P
#!/usr/bin/perl -w package TheServer; use strict; use IO::Select; use Net::Server::PreForkSimple; our @ISA = qw(Net::Server::PreForkSimple); my ($client, $io); # Start the server on port 8000. # Allow 5 connections, run as user/group 'apache' TheServer->run( port => 8000, max_servers => 5, user => 'apache', group => 'apache' ); # Modified chomp() (does \r and \n) sub chom { $_[0] =~ s/\r?\n$// } # New Client Connection sub process_request { my $server = shift; $client = $server->{'server'}; $io = new IO::Select \*STDIN; print "\e[2JConnected from $client->{'peeraddr'}\r\n\r\n"; print "[$client->{'peeraddr'}] "; while (1) { return print "\r\n\r\n30 second timeout reached. Goodbye!\r\n\r\n" unless ($io->can_read(30)); chom( my $in = <STDIN> ); if ($in =~ /^(?:cls|clear)$/i) { print "\e[2J"; } elsif ($in =~ /^(?:date|time)$/i) { print "Date/time: \e[33m", scalar localtime, "\e[0m\r\n"; } elsif ($in =~ /^(?:exit|quit|logout)$/i) { return print "You have successfully logged out.\r\n\r\n"; } else { print "Sorry, I don't understand \e[33m$in\e[0m.\r\n"; } print "[$client->{'peeraddr'}] "; } }
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, please reply to this node or /msg me to inform me as to what is wrong with the post, so that I may update the node to the best of my ability.
In reply to Re: writing to telnet?
by Coruscate
in thread writing to telnet?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |