Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How can I mix Term::ReadLine::Gnu and IO::Sockets to create a telnet/mud client?

by jettero (Monsignor)
on Jan 06, 2006 at 18:14 UTC ( [id://521575]=note: print w/replies, xml ) Need Help??


in reply to How can I mix Term::ReadLine::Gnu and IO::Sockets to create a telnet/mud client?

I just hate answering my own question, because I want to see how someone better at this sort of thing might do it. But I also don't want this question to disappear.

This is a simple IGS client ...

#!/usr/bin/perl use strict; use Term::ReadLine; use IO::Socket; use IO::Select; use threads; use threads::shared; ## This is the IGS go server. Welcome to text mode. ## You must create a username on their website to get this to work my @pair = (qw(igs.joyjoy.net 6969)); my $cmds : shared = ""; my $prompt : shared = "igs> "; my $done : shared = 0; my $term = new Term::ReadLine "igs"; my $listener = new threads( \&listener ); &sender; $listener->join; exit; sub sender { while( defined(my $line = $term->readline($prompt)) ) { lock $cmds; $cmds .= "$line\n"; return if $done; } } sub listener { my $sock = new IO::Socket::INET( PeerAddr => $pair[0], PeerPort => + $pair[1], Proto => "tcp" ) or logger->error("pfft: $!"); my $sele = new IO::Select; my $eb_count = 0; my $last = time+60; $sele->add( $sock ); while( $sock->connected ) { if( $sele->can_read(0.1) ) { my $buf = undef; my $sock_addr = recv( $sock, $buf, 1024, 0 ); if( not defined $sock_addr ) { die "socket error"; } if( not $buf ) { #print "empty \$buf...\n"; if( (++ $eb_count) >= 20 ) { warn "connection terminated\n(return to quit)\n"; $done = 1; return; } } our $ayt; $ayt -- if $ayt and $buf =~ s/(?:\s*|\b)yes\s*(?=\n)//s; $prompt = $1 if $buf =~ s/([^\r\n]+?)$//s; if( $buf ) { print $buf; $term->set_prompt( $prompt ); $term->forced_update_display; $eb_count = 0; } } if( $cmds ) { lock $cmds; print $sock $cmds; $cmds = ""; } if( $last+60 < (my $now = time) ) { our $ayt ++; print $sock "ayt\n"; $last = $now; } } shutdown $sock, 2; }

  • Comment on Re: How can I mix Term::ReadLine::Gnu and IO::Sockets to create a telnet/mud client?
  • Download Code

Replies are listed 'Best First'.
Re: Answer: How can I mix Term::ReadLine::Gnu and IO::Sockets to create a telnet/mud client?
by zentara (Archbishop) on Jan 06, 2006 at 20:06 UTC
    Here is another threaded chat server, from awhile back. It didn't use Term::ReadLineGnu, but it works. It might give you some ideas. ChatServer

    I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found