Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
    
Don't you think that websockets could be an easiest way of solving your problem? –  Eddy_Em Aug 24 '13 at 21:59
    
@Eddy_Em Dont web sockets require a browser? –  tman Aug 24 '13 at 23:17
    
No, they are based on regular sockets but allow you to use them in browsers. –  Eddy_Em Aug 25 '13 at 4:39
    
@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 Aug 25 '13 at 4:45
    
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 Aug 25 '13 at 6:01
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.