#!/usr/bin/perl # #################################### # # JDKCHAT WRITER SERVER # # (Studing sockets) #################################### use strict; use warnings; use IO::Socket; use Net::Telnet; ##################################### #telnet connection my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Port=>2002, Prompt => '/bash\$ $/' ); #socket my $sock = new IO::Socket::INET (LocalHost => 'oni-nux', LocalPort => 8000, Proto => 'tcp', Listen => 5, Reuse => 1, ); die "could not connect: $!" unless $sock; die "can't connect to the chat server: $!" unless $telnet; $telnet->open('localhost'); my @welcome = $telnet->waitfor('/Your Name:$/i'); my $new_sock; my $buf; my $name = 'recipientbot'; chomp $name; $telnet->print($name); my @buffer_in; $telnet->waitfor('/>$/i'); while ($new_sock = $sock->accept()) { while (defined ($buf = <$new_sock>)) { $telnet->print($buf); @buffer_in = $telnet->waitfor('/ >$/i'); print @buffer_in,"\n"; } } close ($sock);