从套接字以及另一个 Erlang 进程接收

发布于 2024-08-21 22:18:57 字数 233 浏览 3 评论 0原文

在 Erlang 进程中,我如何从 ssl 套接字接收数据,同时使用接收原语从另一个 erlang 进程接收数据?

这个想法是将来自套接字的内容转发到另一个进程;和向后。

到目前为止,我唯一的选择是使用一些时间从两端接收,然后切换。当然,这会延迟在一个接口上接收的消息的处理,同时从另一个接口接收消息。你有其他方法可以做到这一点吗?如果 Erlang 让我使用一个进程从套接字接收,并使用另一个进程发送到套接字就好了……

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

霓裳挽歌倾城醉 2024-08-28 22:18:57

不确定我理解你的问题;无论如何,您可以在接收语句中包含多个“子句”,因此当从任何一方接收某些内容时,它都会“解锁”:

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.

重要的是您需要以可以区分 SSL 和处理消息的方式格式化消息与模式匹配。

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.

时光无声 2024-08-28 22:18:57

无论如何,您将通过 receive 语句在进程中从(例如)HTTP_Client 接收消息。您将能够轻松地描述“对话”:

HTTP_Client“对话”的 {http, {RequestId, Result}}

请参阅 此处了解更多详细信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文