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

Jeffrey Rennie <>
Sun Dec 30 18:57:33 CET 2012


Naturally, I find the answer 20 minutes after sending the email: use
handle_info().

> -----Original Message-----
> From: Jeffrey Rennie [mailto:]
> Sent: Sunday, December 30, 2012 9:39 AM
> To: ''
> Subject: How can a gen_server receive messages from a port?
> 
> 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