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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.