sub send_singlecast { my ($NetDeviceID, $Send) = @_; my $Response; # Check if already connected if (! defined $NetDevice[$NetDeviceID]{"Socket"}) { if ($Debug eq "YES") { print "Try to reconnect to Server $NetDevice[$NetDeviceID]{'Name'} ($NetDevice[$NetDeviceID]{'IP'})..."} $NetDevice[$NetDeviceID]{"Socket"} = new IO::Socket::INET ( Broadcast => 0, PeerHost => $NetDevice[$NetDeviceID]{"IP"}, PeerPort => '5000', Proto => 'tcp', Timeout => 2, ); if (defined $NetDevice[$NetDeviceID]{"Socket"}) { if ($Debug eq "YES") { print "success.\n"; } $NetDevice[$NetDeviceID]{"Socket"}->autoflush(1); if ($Debug eq "YES") { print "Enable timeouts.\n"; } IO::Socket::Timeout->enable_timeouts_on($NetDevice[$NetDeviceID]{"Socket"}); $NetDevice[$NetDeviceID]{"Socket"}->read_timeout(2); $NetDevice[$NetDeviceID]{"Socket"}->write_timeout(2); } } if (defined $NetDevice[$NetDeviceID]{"Socket"}) { # Asking for status or sending command $NetDevice[$NetDeviceID]{"Socket"}->send($Send); if ($Debug eq "YES") { print "Command '$Send' send to $NetDevice[$NetDeviceID]{'Name'}, waiting for response..."; } # Read the socket data sent by server $Response=<$NetDevice[$NetDeviceID]{"Socket"}>; if (! $Response && ( 0+$! == ETIMEDOUT || 0+$! == EWOULDBLOCK )) { if ($Debug eq "YES") { print "Timeout by reading from socket!\n"; } write_errorlog("ERROR by reading from Socket : $NetDevice[$NetDeviceID]{'Name'} -> Timeout"); return("ERROR by reading from Socket : $NetDevice[$NetDeviceID]{'Name'} -> Timeout"); } else { if ($Debug eq "YES") { print "received from Server : $Response\n"; } return($Response); } } else { if ($Debug eq "YES") { print "ERROR in Socket Creation : $!\n"; } # Write ErrorLog write_errorlog("ERROR in Socket Creation : <$NetDevice[$NetDeviceID]{'Name'} -> $!"); return("ERROR in Socket Creation : <$NetDevice[$NetDeviceID]{'Name'} -> $!"); } }