PHP UDP Server with Arduino as Client -
i have programmed arduino send massage udp port 8888 when button pressed, , working fine when used third party software such socket test, trying use below php code receive massage.
the code(not code) works, result show when fatal errors , not when send massage(press button)
below sample of result(all result show , not when press button):
socket created socket bind ok waiting data ... 10.10.1.48 : 8888 --yellowwaiting data ... 10.10.1.48 : 8888 -- greenwaiting data ... 10.10.1.48 : 8888 -- yellowwaiting data ... 10.10.1.48 : 8888 -- greenwaiting data ... fatal error: maximum execution time of 120 seconds exceeded in c:\xampp\htdocs\push\udp.php on line 38
below code:
if(!($sock = socket_create(af_inet, sock_dgram, 0))) { $errorcode = socket_last_error(); $errormsg = socket_strerror($errorcode); die("couldn't create socket: [$errorcode] $errormsg \n"); } echo "socket created \n"; if ( ! socket_set_option($sock, sol_socket, so_reuseaddr, 1)) { echo socket_strerror(socket_last_error($sock)); exit; } // bind source address if( !socket_bind($sock, "0.0.0.0" , 8888) ) { $errorcode = socket_last_error(); $errormsg = socket_strerror($errorcode); die("could not bind socket : [$errorcode] $errormsg \n"); } echo "socket bind ok \n"; //do communication, loop can handle multiple clients while(1) { echo "waiting data ... \n"; //receive data $r = socket_recvfrom($sock, $buf, 512, 0, $remote_ip, $remote_port); echo "$remote_ip : $remote_port -- " . $buf; usleep(100000); // debuging purpose ob_flush(); flush(); //send data client socket_sendto($sock, "ok " . $buf , 100 , 0 , $remote_ip , $remote_port); } socket_close($sock);
Comments
Post a Comment