Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Perl as a telnet server?

by osama (Scribe)
on Dec 14, 2002 at 10:14 UTC ( [id://219851]=note: print w/replies, xml ) Need Help??


in reply to Perl as a telnet server?

why not use inetd or xinetd? they handle the sockets, sessions, concurrent connections, and host security parts pretty well...
They would listen to a specified port (23 or any other port, you could telnet hostname XXX to connect to port XXX) and run your script redirecting stdin/stdout to that connection.. Your script can be as simple as you want,dumb example:
#!/usr/bin/perl -w use strict; $|=1; print "What is your name?"; my $name=<>; chomp $name; print "Hello, $name, nice to meet you\n\n"; my $choice=''; while($choice ne 'q') { print "a. Print 1+1\n"; print "b. Print Hi\n"; print "q. Quit!\n"; $choice=<>; chomp $choice; if ($choice eq 'a') {print "1+1=2\n";} if ($choice eq 'b') {print "Hi $name !\n";} }

How to use xinetd on linux/unix:

remeber to disable output buffering $|=1

Simple: create a file /etc/xinetd.d/yourscriptname with

service yourscriptname { disable = no socket_type = stream wait = no user = root server = /path/to/your/script }

also add to your /etc/services:

yourscriptname portno/tcp

There are inetd ports to windows...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://219851]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 12:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found