[erlang-questions] Pass message from C code to Erlang

Alexander Kuleshov <>
Sat Aug 20 19:00:36 CEST 2011


2011/8/20 Alexander Kuleshov <>

> 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.
>
> And i get error:

[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0x08055fac in ei_mutex_lock ()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110820/1f6fe41f/attachment.html>


More information about the erlang-questions mailing list