#!/usr/bin/perl -w # # $Id: perl_example,v 1.1 2007-01-03 22:34:23 matthias Exp $ # # Author: Matthias Lang (matthias@corelatus.com) # Created: December 2000 # # Use: # # ./perl_example # # This is a demonstration of the shortest possible (well, I'm sure # there's a shorter way...) PERL program which can make the GTH # loopback a timeslot. # # Kill with ^c or equivalent when you've had enough. #---------------------------------------------------------------------- use IO::Socket; $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $ARGV[0], PeerPort => "2089", ) or die "cannot connect to GTH port 2089 on remote host"; $content = "" . "" . "" . "" . "" . ""; print $remote "Content-type: text/xml\r\n"; print $remote "Content-length: ", length($content), "\r\n\r\n"; print $remote $content; <$remote>; # content-type reply $_ = <$remote>; # content-length reply (/Content-length: ([0-9]+)/) || die("unexpected reply from GTH"); read($remote, $content, $1+2); # +2 for extra \r\n print("Reply: $content\n");