#!/usr/bin/perl -w use strict; use IO::Socket; use Term::ReadKey; ReadMode 1; my ($PORT, $server, $client); $PORT = 9000; # pick something not in use $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $PORT, Listen => SOMAXCONN, Reuse => 1 ); die "can't setup server" unless $server; print "[Server accepting clients]\n"; while ($client = $server->accept()) { $client->autoflush(1); print "Received connection!\n"; while (1) { my ($key); while (not defined ($key)) { $key = ReadKey(-1); } print "Get key $key\n"; print $client "$key\n"; $key = ReadKey(-1); #clear $key } } close $client; ReadMode 0; #### #!/usr/bin/perl -w use strict; use IO::Socket; use Win32::GuiTest qw(:ALL); my $host = shift || 'localhost'; my $port = shift || '9000'; my ($kidpid, $socket, $line); # create a tcp connection to the specified host and port $socket = IO::Socket::INET->new( Proto => 'tcp', PeerAddr => $host, PeerPort => $port ) or die "can't connect to port $port on $host: $!"; print "[Connected to $host:$port]\n"; while (1) { while (defined ($line = <$socket>)) { sleep(1); chomp($line); SendKeys($line); print "$line\n"; } }