I have a service on a server that listen to a UDP port. how can I check my service still listen on this port or not by php?
I think UDP is one-way and don't return anything on create a connection (in fact there is no connection :)) and I should write to a socket.
but, whether I write successfully to a socket or not, I receive 'true'!
my code:
if(!$fp = fsockopen('udp://192.168.13.26', 9996, $errno, $errstr, 1)) {
echo 'false';
} else {
if(fwrite($fp, 'test')){
echo 'true';
}else{
echo 'false';
}
}
do you have any suggestion for this?
As PHP official documentation said
So you can do this to check the error
You should really switch to the Sockets library for creating sockets:
The only way to see if a socket is still open is to post a message to it, but given the nature of UDP there are no guarantees.