$gui = Gui->new ; $gui->buildGui(); $server = Server->new; $server->startServer() ; #forks a client process system("perl client.pl"); #### sub new { my $class = shift; my %args = @_; my $self = { guiObj => $args{guiObj}, }; $self->{buffer} = "" unless defined $self->{buffer}; bless $self, $class; return $self; } sub startServer { my $self = shift; my $guiobj = $self->{guiObj}; my $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => 55555, Listen => SOMAXCONN, Reuse => 1 ) or die "Server can't start: $!"; my $readable_handles = new IO::Select(); $readable_handles->add($server); $guiobj->{parentWnd}->after( 10000, [ \&dump_count, $self ] ); $guiobj->{parentWnd} ->repeat( 1, [ \&checkData, $self, $server, $readable_handles ] ); } sub checkData { # this function checking the socket and whenever it is #readable, reads the data into $self->{buffer} and calls #the updateDisplay() of the Gui.pm with that read data if ( $sock->sysread( $buf, 16 * 1024 ) ) { $self->{buffer} .= $buf; my $databuf = $self->{buffer}; $self->{guiObj}->updateDisplay($databuf) } sub dumpCount { # dumps the data sent to the gui after every 10ms in a file #which stores it in a hash structure where hash keys are #timestamps } #### $cl = ClinetModule->new(); $cl->startClient() #### sub new { my $class = shift; my $self = { }; bless $self, $class; return $self; } sub startClient { my $self = shift; my $client = IO::Socket::INET->new( Proto => 'tcp', PeerAddr => 'localhost', PeerPort => 55555 ) or die "Client can't connect: $!"; $self->{client} = $client; $client->blocking(0); $client->autoflush(1); while (1) { my @color = qw(red green yellow magenta skyblue ); my @status = qw(pending queued running finished stopped); foreach ( 1 .. 1000 ) { my $randRow = int( rand($range) ) + 1; my $color = $color[ rand(@color) ]; my $state = $status[ rand(@status) ]; my $data = $randRow . " " . $state . " " . $color . " "; my $bytes = $self->{client}->syswrite($data); } usleep(100000); # hangs # usleep(500000); #better #sleep 1; #works fine } }