use io;
use Carp;
use Gtk -init;

my $sock = Gtk::io::INET->new(Proto 		=> 'tcp',
										LocalPort => 9400,
										Listen    => 2,
										Reuse     => 1) 
  or die "Could not open  server socket on port 9400";

if(fork()){
  # The Server
  my $client;
  while($client = $sock->accept()){
	 while(<$client>){
		if(/DONE/){
		  $client->close;
		  sleep(1);
		  exit;
		}
		print "$_\n";
	 }
  }
  

}else{
  #The Client

  my $socket = Gtk::io::INET->new(Proto => 'tcp',
										PeerAddr=> 'localhost',
										PeerPort=> 9400) 
	 or die "Could not connect to server";


  $socket->blocking(0);

#  my $time = $socket->timeout;
#  print "Time = $time\n";
#  $time = $socket->timeout;
#  print "Time = $time\n";

  my $buffer;
  my $len = 0;
  $socket->sysread($buffer,4,$len);
  
  $time = $socket->timeout(5);
  print "Time = $time\n";
  $socket->sysread($buffer,4,$len);

  $socket->syswrite('DONE',4);
  exit;
}
