So I have a webserver in which user can remotely control an external electronic board which due to certain conditions force me to put a desktop program using C# as the middle-man.
What is the magic keyword I'm looking for? At first I thought of socket but every socket searches involve server-client over TCP... it's the same machine so theoretically I can just put loopback address and proceed normally. But is this an overkill way or the only way?
Thanks in advance.
edit: My C# program is basically a daemon which will wait orders from the PHP script. So I can remotely access that website and instruct that C# app.
I would suggest client/server architecture using TCP/IP (or even UDP) (or another MS messaging protocol) in order to talk to your C# program. What you are effectively doing is writing a device driver for a specialized piece of hardware. By making it client/server you can:
I'm not 100% sure what you mean. I assume you want to call a C# app from within a php script. If so, maybe this will help:
function execute($command, $stdin) {
$pipes = array();
$process = proc_open($command, array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes);
if ($stdin) fwrite($pipes[0], $stdin);
fclose($pipes[0]);
$stdout = '';
while(!feof($pipes[1])) $stdout .= fgets($pipes[1], 1024);
fclose($pipes[1]);
$stderr = '';
while(!feof($pipes[2])) $stderr .= fgets($pipes[2], 1024);
fclose($pipes[2]);
$return_value = proc_close($process);
return array($stdout, $stderr, $return_value);
}
Where $command is the path and file name of your c# app (plus any command line params) and if needed $stdin is, well, standard input to your c# app.
If your C# app is listening on a particular port (lets say 8888) for requests, maybe you're looking for:
$handle = fopen("http://localhost:8888/someurl?someparam=somevalue", "r");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.