[erlang-questions] Pass message from C code to Erlang
Alexander Kuleshov
kuleshovmail@REDACTED
Sat Aug 20 18:53:56 CEST 2011
Hello,
I try to send message from C code to erlang. I use EI Library.
My C code:
int main (int argc, char** argv)
{
erl_init (NULL, 0);
extern const char *erl_thisnodename(void);
extern short erl_thiscreation(void);
#define SELF(fd) erl_mk_pid(erl_thisnodename(), fd, 0,
erl_thiscreation())
ETERM *arr[2], *emsg;
int sockfd, creation=1;
arr[0] = SELF(sockfd);
arr[1] = erl_mk_atom("ok");
emsg = erl_mk_tuple(arr, 2);
erl_reg_send(sockfd, "my_server", emsg);
erl_free_term(emsg);
return (EXIT_SUCCESS);
}
And my erlang code:
start() ->
Pid = spawn(?MODULE, loop, []),
register(my_server, Pid).
loop() ->
receive
{ok} ->
io:format("Ok received \n"),
loop();
stop ->
stop;
_ ->
io:format("Somethig else \n")
end.
stop() ->
my_server ! stop.
But when i run my C application, erlang application nothing received. What's
wrong?
Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110820/3c612a14/attachment.htm>
More information about the erlang-questions
mailing list