<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w
use strict;
use IO::Socket;

sub connect_client {
    my ( $remote, $port );
    my ( $iaddr, $paddr, $proto, $line );
    
    $remote  = shift || 'localhost';
    $port    = shift || 2342;  # random port

    my $conn_hand = IO::Socket::INET-&gt;new(
				    Proto    =&gt; "tcp",
				    PeerAddr =&gt; $remote,
				    PeerPort =&gt; $port
				       )
	or die "ERROR: Cannot connect to port $port at $remote\n";

    $conn_hand-&gt;autoflush(1);
    print $conn_hand "get termsize\n";
    # send( SOCK, "get termsize\n", 0);
    my ( $cols, $rows ) = ( 0, 0 );
    if (defined(my $line = &lt;$conn_hand&gt;)) {
	print $line;
	if ( $line =~ /^cols:\s(\d*?),\srows:\s(\d*?)$/ ) {
	    $cols = $1;
	    $rows = $2;
	    print "termsize: ok $cols $rows\n";
	    return(0, $conn_hand, $cols, $rows);
	} else {
	    print "termsize: error";
	    return(1);
	}
    }
}


sub disconnect_client{
    close ($_[0])            || die "close: $!";
}

my ( $retval, $conn_hand, $cols, $rows ) = connect_client();
if ( $retval != 0 ) {
    die "ERROR: Couldn't establish a connection.\n";
}
disconnect_client( $conn_hand );
exit;

</pre></body></html>