sub ReadData{ my $recv_data; my $send_data; my $command; my $working_data; while ($endEx eq "false"){ if ($connected eq "true") { $socket->recv($recv_data,1024); if ($recv_data ne "") { # make sure, we can read from the socket, if ($debug_log eq "on") { &WriteLog("Message received: $recv_data"); } $command = substr($recv_data , 0 , 3); if ($command eq "GET"){ $send_data = "OLD:" . &GetCurrent; } elsif ($command eq "PUT"){ $working_data = substr($recv_data , 4); &SetNew($working_data); $send_data = "NEW:" . &GetCurrent; } #elsif ($command eq "SET"){ #will be used in the future for setting startstop handling #} if ($command eq "GET" || $command eq "PUT"){ $socket->send($send_data); if ($debug_log eq "on") { &WriteLog("Message sent: $send_data"); } } } else{ $connected = "false"; # if not, reset socket and reconnect Win32::GUI::NotifyIcon::Change( $ni, -icon => $icon_no, -tip => "connecting...", ); } usleep($reconnecttime); } else { &WriteLog("Connection lost"); close $socket; $socket=""; &ConnectServer(); } } }