receive from a socket and also from another Erlang process
in an Erlang process, how could i receive from an ssl socket, and at the same time receive from another erlang process with the receive primitive?
the idea is to forward what comes from the socket to another process; and backwards.
my only option so far is to use some time receiving from each end, then switch. that, of course, will delay the processing of the messages received on one interface, while receiving from the other one. 开发者_开发知识库 do you see any other way to do this? if only Erlang would let me use one process to receive from the socket, and another one to send to the socket...
Not sure I understand your question; anyway, you can have multiple "clauses" in a receive statement, so it becomes "unblocked" when receiving something from either side:
loop() ->
receive
{ssl, Msg} -> % incoming msg from SSL, send it to process
Proc ! Msg,
loop();
{proc, Msg} -> % incoming msg from process, send it to SSL
SSL ! Msg,
loop()
end.
The important thing is that you need to format your messages in a way that you can differentiate between SSL and process messages with pattern matching.
You'll anyhow receive the message from (e.g.) an HTTP_Client in a process through the receive
statement. You'll be able to delineate the "conversations" easily:
{http, {RequestId, Result}}
for the HTTP_Client "conversations"
See here for more details.
精彩评论