sockets - How to check UDP port listen or not in php? -


i have service on server listen udp port. how can check service still listen on port or not php?

i think udp one-way , don't return on create connection (in fact there no connection :)) , should write socket.

but, whether write socket or not, 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 have suggestion this?

you should switch sockets library creating sockets:

$ip = '192.168.13.26'; // create udp socket if(!($sock = socket_create(af_inet, sock_dgram, sol_udp))) {     $errorcode = socket_last_error();     $errormsg = socket_strerror($errorcode);      die("couldn't create socket: [$errorcode] $errormsg \n"); }  // bind source address if( !socket_bind($sock, $ip, 9996) ) {     $errorcode = socket_last_error();     $errormsg = socket_strerror($errorcode);      die("could not bind socket : [$errorcode] $errormsg \n"); } 

the way see if socket still open post message it, given nature of udp there no guarantees.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -