php - Communicate a button click event with sockets -
desire: have device or micro-controller i'll call mc need communicate when web page button clicked using sockets.
mc1 <button id ='on1' name='mc1'>on</button> <button id ='off1' name='mc1'>off</button>
details: trying accomplish when button clicked pass info mc.
what tried: can listens port , can write data mc receive data. im starting file though server php cli. file contains these basic socket functions.
$socket = @socket_create_listen("port#"); $client = socket_accept($socket); socket_write($client, $msg); socket_read ($client, 256);
the mc connect server @ port#
problems: im having difficulties understanding how bridge gap between php web page button , passing data button has been clicked mc.
attempt @ solution: can have file listens port run , in seperate file write client?
additional notes: mc lan avoid setting port forwarding , external ip changes. these reason had choose have mc establish connection server allowing server write mc without needing port forwarding , non changing ip address.
thanks jt
the simplest way create simple program (php fine) runs in web server (like apache, whatever). whenever called, synchronously opens socket mc , sends data.
you wouldn't write code open listening socket, php open client socket mc socket_connect, send data, close socket.. return status web client.
Comments
Post a Comment