Hello all,
I'm tring to write the simplest telnet server that will read characters from the client by the character and not by the word (waiting for "\n").
I've already searched the web and found a module, NetServer::Generic, that will let me build a simple telnet server.
I've also found on the web the module, Term::ReadKey, that will let me change the way perl read info from the user, which will be by character.
The problem is that they don't work together, any idea?
Here is my program:
#!perl -w
use strict;
use NetServer::Generic;
use Term::ReadKey;
sub Terminal
{
my ($server) = @_;
my $input;
my $key;
while (1)
{
ReadMode(4);
while (not defined ($key = ReadKey(0))) {};
ReadMode(0);
if ($key eq "q")
{
return 1;
}
else
{
print "Got character '" . ord($key) . "'\r\n";
}
};
return 0;
}
my $Server = new NetServer::Generic;
$Server->port(23);
$Server->callback(\&Terminal);
$Server->mode("forking");
print "Starting server\n";
$Server->run();
The problem is that the call to "ReadMode(4)" result in error and close of the client:
"GetConsoleMode failed, LastError=|6| at C:/Perl/lib/Term/ReadKey.pm line 265"
BTW, the script should run on linux and windows.
Thanks,
Dayan Shay
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.