Communicate a button click event with sockets

1

Desire: I have a device or micro-controller i'll call it a mc that I need to communicate to when a web page button is clicked using sockets.

MC1
<button id ='on1' name='mc1'>On</button>
<button id ='off1' name='mc1'>off</button>

Details: What I am trying to accomplish is when a button is clicked pass the info to the mc.

What I Tried: Currently I can listens to a port and can write data to the mc as well as receive data. To do this im starting a file though the server php cli. The 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 then connect to the server at the port#

Problems: Im having difficulties understanding how to bridge the gap between my php web page with the button and passing the data that the button has been clicked to the mc.

Attempt at a Solution: Can i have the file that listens to the port run and then in a seperate file write to the client?

additional notes: The MC LAN I would like to avoid setting up port forwarding and the external ip sometimes changes. For these reason I had choose to have the MC establish the connection to the server thus allowing the server to write to the MC without needing port forwarding and a non changing ip address.

Thanks JT

tman

Posted 2013-08-24T20:22:20.450

Reputation: 113

Don't you think that websockets could be an easiest way of solving your problem? – Eddy_Em – 2013-08-24T21:59:08.443

@Eddy_Em Dont web sockets require a browser? – tman – 2013-08-24T23:17:59.270

No, they are based on regular sockets but allow you to use them in browsers. – Eddy_Em – 2013-08-25T04:39:57.857

@Eddy_Em can web sockets be used without a browser is my question. I was under the assumption web sockets required a browser that could interpret client side scripting such as javascript. – tman – 2013-08-25T04:45:43.420

Websockets allow you to use both browser and console application. In case of regular sockets you can't use browser and need to write some intermediate CGI, – Eddy_Em – 2013-08-25T06:01:38.220

Please don't use tags where it says DO NOT USE such as server and communication! thanks. – user 99572 is fine – 2013-08-25T17:49:28.963

No answers