linux - Communicate a button click event with sockets

06
2014-04
  • tman

    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

  • Answers
    Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

    Related Question

    force all sockets to close in linux
  • lathomas64

    How can I force all currently open sockets in linux to close from the command line?


  • Related Answers
  • cYrus

    Maybe it's easier to shut down a specific interface, for example:

    # ifconfig eth0 down
    
  • someguy

    to flush all your rules in the filter table iptables -F
    set default behavior to drop in INPUT chain iptables -P INPUT DROP

    at this point all local sockets should be unavailable to a remote host if you have a redhat based os you should also use iptables -X to get rid of their custom chain for INPUT

    if you want to the rules to remain on startup then you need to either include these in a script that runs in the /etc/rc.local file or use iptables save

    This is all assuming that what you said you want to do is what you want to do.