[erlang-questions] Can Ports be used for initiating calls to Erlang?

Michael Truog mjtruog@REDACTED
Thu Oct 18 21:50:12 CEST 2012


On 10/18/2012 08:18 AM, Yash Ganthe wrote:
> Hi,
>
> From the erlang docs, the method for sending data to a C program is:
> receive
> {call, Caller, Msg} ->
> Port ! {self(), {command, encode(Msg)}},
> receive
> {Port, {data, Data}} ->
> Caller ! {complex, decode(Data)}
> end,
> loop(Port);
>
> This means a message sent to the Port with "command" goes to the STDIN of the C prog and the C prog responds with "data".
>
> Is it possible and customary to use the same mechanism to have a C program INITIATE calls to an Erlang module? Is it common to have C programs invoke Erlang functions by sending a "data" on STDOUT and waiting for the response on STDIN?
>
> Thanks,
> Yash
>
Yes, but you often have to be careful of the types you use.  You probably don't ever want to try to create an anonymous erlang function in C code that is called by Erlang code, after the data is received within the Erlang node.  If you want a consistent framework for bidirectional integration (using Erlang ports) with C/Erlang (including C++, Java, Python, and Ruby, currently), you might want to try a project I have here: http://cloudi.org



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121018/82dd5e45/attachment.htm>


More information about the erlang-questions mailing list