- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
您好,我是 DBus 守护进程的新手,我想在 C 应用程序和 python 应用程序之间完成简单的消息交换,它们在自定义的类 linux 环境中运行。我的理解是
我的问题是关于上面的 (2) 和 (3)。 C应用程序和python应用程序如何注册到同一总线?
此外,需要调用哪些 API 才能在这两个应用程序之间发送字符串消息?
最佳答案
[您要求简单的消息传递]
如果您要求在 C 应用程序和 Python 之间传递简单的消息,为什么不使用像 Rabbit/ZeroMQ 这样的消息传递库?这些已经解决了与传递/接收消息相关的所有问题。
而且,如果您想将依赖性保持在最低限度,您可以使用 UNIX 套接字或什至一些简单的 TCP/UDP 数据报。
编辑:因为我试图说服您研究 ZeroMQ 作为您的 IPC 平台以及它是多么简单,这里有一个示例 C“客户端”向服务器发送完整的数据报,服务器回复。
// Hello World client
#include <zmq.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
int main ( void )
{
printf ( "Connecting to hello world server…\n" );
void *context = zmq_ctx_new ();
void *requester = zmq_socket ( context, ZMQ_REQ );
zmq_connect ( requester, "tcp://localhost:5555" );
int request_nbr;
for ( request_nbr = 0; request_nbr != 10; request_nbr++ ) {
char buffer [10];
printf ( "Sending Hello %d…\n", request_nbr );
zmq_send ( requester, "Hello", 5, 0 );
zmq_recv ( requester, buffer, 10, 0 );
printf ( "Received World %d\n", request_nbr );
}
zmq_close (requester);
zmq_ctx_destroy (context);
return 0;
}
服务器也同样简单:
// Hello World server
#include <zmq.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
int main ( void )
{
// Socket to talk to clients
void *context = zmq_ctx_new ();
void *responder = zmq_socket ( context, ZMQ_REP );
int rc = zmq_bind ( responder, "tcp://*:5555" );
assert ( rc == 0 );
while ( 1 ) {
char buffer [10];
zmq_recv ( responder, buffer, 10, 0 );
printf ( "Received Hello\n" );
sleep ( 1 ); // Do some 'work'
zmq_send ( responder, "World", 5, 0 );
}
return 0;
}
关于python - 使用 DBus 守护进程将消息从 C 应用程序交换到 python 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39577527/
一 点睛 线程可以设置为守护线程,ThreadGroup 也可以设置为守护 ThreadGroup,但是若将一个 ThreadGroup 设置为 deamon,也并不会影响线程的 daemon 属性,
我有一个 python 脚本需要在启动时作为守护进程运行。进程从 tty(和 pdb)分离,但代码不运行。 我已经将它缩小到一个最小的例子 import daemon from time import
reactjs isMounted API 的文档提到: You can use this method to guard asynchronous calls to setState() or fo
我正在开发一个需要嵌入 HTTP 服务器的守护进程。我正在尝试使用 BaseHTTPServer 来完成它,当我在前台运行它时,它工作正常,但是当我尝试将守护进程 fork 到后台时,它停止工作。我的
我正在尝试使用 Apache Commons Daemon 使用 Daemon 接口(interface)来守护我的应用程序。 Java 应用程序本身不执行任何操作,只是写入 stout。 我编译了j
我正在使用 Bootle Python Web Framework 在 Ubuntu 上开发网络应用程序。是否有任何有效的方法来守护启动默认 bottlepy 网络服务器的脚本? 谢谢。 UPD:现在
我一直使用 bluepill成功地守护简单的 Ruby 脚本。然而这一次,我有一个脚本,它也在加载 Rails 环境,因此我可以访问 Rails 应用程序及其各自模型的数据库连接。我使用的 bluep
我试图守护一些代码,但我遇到了一些麻烦。 如果我用 tklogger() 调用代码,它运行得很好。但是,如果我在守护程序上下文中调用它,我会得到以下跟踪信息: Traceback (most rece
我打算使用 systemd 将 celery 4.3.0 作为守护进程运行,但它给了我这个错误: 它会启动 worker 但会很快停止它们。但是,我可以通过键入以下命令手动运行工作人员: celery
我是一名优秀的程序员,十分优秀!