Good morning! I have the following PHP code to send commands via UDP:
function sendPacket($packet, $ip, $port){
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($socket, SOL_SOCKET, SO_BROADCAST, 1);
$message = '';
foreach ($packet as $chunk){ //Esto es porque se espera un array de bytes
$message .= chr($chunk);
}
socket_sendto($socket, $message, strlen($message), 0, $ip, $port);
socket_close($socket);
}
The packages I send are of the style:
const Ejemplo = array(0x12, 0x05, 0xb0);
The issue is that for certain commands, the receiver should send a response, an "OK", and I already gave a thousand laps and can not find the method to listen. I tried doing a connect / bind and using recvfrom, but nothing worked. I would need to find a way, using the previous function to send the command, to automatically listen to me to wait for the answer if there was one, at least for a limited time.