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

Gleb Peregud <>
Thu Oct 18 17:25:39 CEST 2012


On Thu, Oct 18, 2012 at 5:18 PM, 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?

Yes



More information about the erlang-questions mailing list