[英]Best practice for an AJAX call to running C code?
I have an underlying C application driving some pretty intensive hardware. 我有一个底层的C应用程序,用于驱动一些非常密集的硬件。 I'm currently designing a web interface for the device, the majority of it's function is to present status information to the user.
我目前正在为设备设计一个Web界面,其大部分功能是向用户显示状态信息。 So every second or so, update fields on the web page with pertinent information (temperature, framerate, yada yada...) The device runs linux and has apache.
因此,每隔一秒钟左右,用相关信息(温度,帧速率,yada yada ...)更新网页上的字段。该设备运行linux并且具有apache。 Current setup:
当前设置:
Here's where you come in... the goal is to take out the PHP middleman. 这是您进入的地方...目标是淘汰PHP中间人。 What are the conventions (assuming they exist) for AJAX calls to C programs?
AJAX调用C程序有哪些约定(假设它们存在)? Best practice?
最佳实践?
Options (as far as I know): 选项(据我所知):
Any insight appreciated. 任何见解表示赞赏。 Of course, the best answer is quite possibly not even listed above.
当然,最好的答案甚至可能没有在上面列出。 That's just the extent of my knowledge in this area.
那只是我在这方面知识的程度。 Thanks!
谢谢!
We have used the C library libwebsockets ( http://libwebsockets.org/ ) to communicate between JavaScript and a C++ application. 我们已经使用C库libwebsockets( http://libwebsockets.org/ )在JavaScript和C ++应用程序之间进行通信。 In our case we send JSON to and from the C++ backend via websockets.
在我们的例子中,我们通过websockets向C ++后端发送JSON。
In your case you could take the same data that you currently send via Ajax and send it to the C program over the websocket. 在您的情况下,您可以获取当前通过Ajax发送的相同数据,然后通过websocket将其发送到C程序。 The C program can then generate the same JSON that the PHP program generates and send that back to the JavaScript, again via the websocket.
然后,C程序可以生成与PHP程序生成的JSON相同的JSON,然后再次通过websocket将其发送回JavaScript。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.