erlang 关于套接字的一般问题
我对我应该为分布式系统课程实施的项目有疑问。
该项目包括设计和实现一个库,为用户进程提供可靠的多播服务。所有进程都属于一个组,消息由成员进程发送给该组的所有成员。发件人被排除在收件人列表之外。
在我看来,由于它的消息传递结构,这在 erlang 中很容易实现...如果您使用 rpc 调用而不是基于普通套接字的实现,则会给出更多要点。
现在我的问题是:这个的强制性要点之一项目要求当进程之间没有通信时,套接字不保持打开状态...
我们的课程是用 C 语言进行的,但我们可以自由地使用我们喜欢的任何语言...我可以使用 erlang 节点来满足这个约束吗rpc 调用?
提前致谢
I have a question about a project I should implement for my Distributed System course.
The project consist in designing and implementing a library that provides a reliable multicast service to user processes. All processes belong to a group, and a message is sent by a member process to all members of the group. The sender is excluded from the recipient list.
This seems to me quite easy to implement in erlang, due to its message passing structure...more points are given if you use rpc call instead of normal sockets based implementation..
Now my question is this: one of the mandatory points of this projects requires that sockets aren't kept open when there is no communication going on between processes...
Our course is held in C, but we are free to use any language we like...can I satisfy this constraint using erlang nodes and rpc calls?
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。 rpc 模块甚至有
multicall
,它需要节点列表并将完全按照您所描述的操作。当它不使用它们时,它也不会保持你的套接字打开。Yes. The rpc module even has
multicall
, which takes a list of nodes and will do exactly what you described. It won't hold your sockets open when it's not using them either.不管其他答案怎么说,Erlang 的默认行为并不满足您的约束。
使用 Erlang 发行版的典型 Erlang 节点网络将保持密集连接(每个节点都连接到每个其他节点),并且 TCP 套接字打开,即使您不使用它们也是如此。您要么必须使用 -connect_all false 并自行管理打开/关闭与其他节点的连接,要么必须开发自己的分发协议。我会推荐后者,特别是因为你正在学习。使它变得简单的技巧是使用 term_to_binary 和 binary_to_term。
Despite what the other answers say, Erlang's default behavior does not satisfy your constraints.
A typical network of Erlang nodes using Erlang distribution will remain densely connected (every node connected to every other node) with TCP sockets open even when you're not using them. You will either have to use -connect_all false and manage opening/closing the connections to other nodes yourself, or you will have to develop your own distribution protocol. I would recommend the latter, especially since you are learning. The trick to make it easy is to use term_to_binary and binary_to_term.