如何向远程 Elixir GenServer 发送消息,然后使用C Erlang 接口接收调用结果?
我想在 C 中运行类似于
{result1, result2} = GenServer.call(MyModule.NodeName, {:dothing, "blah"})
这是我到目前为止所拥有的。它编译并连接到远程服务器并运行ei_reg_send
而不会导致错误,但远程服务器没有收到响应。(我打开了一个记录器,所以我知道什么时候来电。)
#include <erl_interface.h>
#include <ei.h>
#define COOKIE "cookieval"
#define HOST "name@host"
int main() {
ei_init();
ei_cnode ec;
int n = 0;
int sockfd;
int self;
if((self = ei_connect_init(&ec, "nss", COOKIE, n++)) < 0) {
return 1;
}
if((sockfd = ei_connect(&ec, HOST)) < 0) {
return 2;
}
ei_x_buff request;
ei_x_new(&request);
ei_x_format(&request, "{dothing, ~a}", "blah");
if(ei_reg_send(&ec, sockfd, "MyModule.NodeName", request.buff, request.index) < 0) {
return 3;
}
ei_x_free(&request);
// code makes it to here, but there's no indication that the genserver was called
return 0;
}