use Tk; use IO::Socket; use strict; use English; require Tk::DialogBox; if (defined $ARGV[0]){ my $sock = new IO::Socket::INET ( PeerAddr => 'localhost', PeerPort => '7071', Proto => 'tcp', ); die "Could not create socket: $!\n" unless $sock; print $sock "name=Player1!"; close($sock); exit; } my $mw = MainWindow->new; &waiting; MainLoop; sub waiting{ my $sock; my $pid; my $name; pipe READOUT, WRITEOUT or die "can't pipe"; $pid = fork(); if ($pid){ my $db = $mw->DialogBox( -title => "Waiting for users", -buttons => [ "Cancel" ] , -command => sub {kill(30,$pid);}, ); $db->add( "Label", -text => " \n\n")->pack(); $db->Show(); close(WRITEOUT); my $in = ; print "parent received $in\n"; close(READOUT); } else { close(READOUT); open(STDOUT, ">&WRITEOUT"); sub SeeYa { print "\n";close(STDOUT);close(WRITEOUT);} $SIG{'USR1'} = SeeYa; for (my $i=1; $i<6; $i++){ $sock = new IO::Socket::INET ( LocalHost => 'localhost', LocalPort => 7071, Proto => 'tcp', Listen => 1, Reuse => 1, ); die "Could not create socket: $!\n" unless $sock; my $new_sock = $sock->accept(); my $input; while(defined(my $in = <$new_sock>)) { $input = $in; } ($_,$name) = split(/=/,$input); close($sock); print "$name\n"; } } }