[erlang-questions] How can a gen_server receive messages from a port?

Jeffrey Rennie <>
Sun Dec 30 18:38:39 CET 2012


I'm building a gen_server that communicates with an external process via an
erlang port.

Sending messages to the port is straight-forward.

However, I haven't yet figured out how to get my gen_server to Receive
messages from the port.  I've tried the following, but to no avail:

handle_cast({Port, {data, Binary}}, State)
  when is_port(Port); is_binary(Binary) ->
    Term = binary_to_term(Binary),
    io:format("Received data on port: ~w~n", [Term]),
    handle_port(Term, State);

How can a gen_server receive messages from a port?

Sincerely,
Jeffrey Rennie




More information about the erlang-questions mailing list