sub main_connection { my $text = shift;#prompt-msg sleep(30) unless $FST;#provide serverflooding $FST = 0; print "$text\n"; $SPIN = shake_hands(); login(); #use select to have a non-blocking socket my $sock = new IO::Select( $SPIN ); main_loop($sock); } #sub main_connection sub main_loop { my $sock = shift; my $died = 0;#check flag while (1) { #get data from socket, if there some while ((my @ready = $sock->can_read(30))) { #print "test1\n"; for my $fh (@ready) {#checkout readable fhs if($fh == $SPIN) { my $input; unless(sysread($SPIN,$input,2048)) { $died = 1 }; last if $died; if($input) { #print "test2\n"; ping_check(); #in some cases we've more than one cmd in a line #so we've to split them by \n, cause server seperates by \n my @cmds = split /\n/, $input; for my $line (@cmds) { open_log() unless check_log("logs/$logfile"); start($line); #print "test3\n"; } } else { print "unknow socketerror...\n";#syswrite returns 1, but we haven't some input? } last; } } last if $died; } last if $died; ping_check() or last; print "Nichts passiert!\n"; } main_connection('Socketerror, trying to reconnect..'); } #main_loop()