quixadhal has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Wise Ones!

I am attempting to write a small telnet server, for the purpose of reviving an ancient text-based game as a client/server in perl, rather than the file-based C gremlin it was.

I'd like to allow folks to use their favorite telnet client, rather than forcing them to use a custom one.

So far, I'm using a simple non-blocking select loop (with IO::Socket::INET), and have found Net::Telnet::Options to help tame the protocol. With that, it's not hard to place the telnet client into single-character mode. I can also negotiate the terminal type and size, assuming the client isn't totally brain dead.

The point at which I'm unsure of my path is trying to get the Curses module to work with a socket as the "display", rather than trying to find my local pty. I'll also need to have multiple instances of Curses, one for each connected client.

How might I convince the mighty Curses module to believe me when I tell it the terminal characteristics, and to use a lowly socket as if it were a true pty?

Thank you!

Replies are listed 'Best First'.
Re: Curses and Sockets
by Withigo (Friar) on Oct 09, 2007 at 04:10 UTC
    3 minutes of searching comp.lang.perl.misc came up with this solution
    Good luck!
      Just in case it's not so clear how that link demonstrates a possible solution, Curses uses STDIN, STDOUT, STDERR. So in a BEGIN block before initializing Curses, create a new IO pty and then redirect the standard file handles to/from it like in the example script in the link. Then Curses is connected to the pty.
      Hope it works!
        Hmmm, sounds promising!

        I suspect I'll have to switch to a multi-threading model so each client socket can have a separate thread and thus keep its own copy of Curses to play with.

        Thanks again!