[英]PHP webserver connect to C# program on same server — What am I looking for?
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. 因此,我有一个Web服务器,用户可以在其中远程控制外部电子板,由于某些条件,该电路板迫使我使用C#作为中间人来放置桌面程序。
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.
起初,我想到了套接字,但是每个套接字搜索都涉及TCP上的服务器-客户端...这是同一台机器,因此从理论上讲,我可以放回送地址并正常进行。 But is this an overkill way or the only way?
但这是一种矫kill过正的方法还是唯一的方法?
Thanks in advance. 提前致谢。
edit: My C# program is basically a daemon which will wait orders from the PHP script. 编辑:我的C#程序基本上是一个守护程序,它将等待来自PHP脚本的命令。 So I can remotely access that website and instruct that C# app.
因此,我可以远程访问该网站并指示该C#应用程序。
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. 我建议使用TCP / IP(甚至UDP)(或其他MS消息传递协议)的客户端/服务器体系结构,以便与您的C#程序对话。 What you are effectively doing is writing a device driver for a specialized piece of hardware.
您实际上正在做的是为专用硬件编写设备驱动程序。 By making it client/server you can:
通过使其成为客户端/服务器,您可以:
Edit
编辑
I'm not 100% sure what you mean. 我不确定100%的意思。 I assume you want to call a C# app from within a php script.
我假设您想从php脚本中调用C#应用程序。 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. 其中$ command是c#应用程序的路径和文件名(加上任何命令行参数),如果需要,$ stdin是c#应用程序的标准输入。
If your C# app is listening on a particular port (lets say 8888) for requests, maybe you're looking for: 如果您的C#应用正在特定端口(例如8888)上侦听请求,那么您可能正在寻找:
$handle = fopen("http://localhost:8888/someurl?someparam=somevalue", "r");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.