发送和接收 RPC 的函数名称?
我用的是扭曲的。我设置了协议,以便发送 RPC,我执行 protocol.send("update_status", data)
。为了记录我已实现的 RPC,我对每个 RPC 进行了单独的函数调用,因此在本例中,我将调用 REQUEST_UPDATE_STATUS(data)
来发送该 RPC。当协议收到 RPC 时,会根据其名称调用一个函数,在本例中为 CMD_UPDATE_STATUS
。
问题是 REQUEST
和 CMD
有点尴尬。我可能会将 REQUEST
误认为是命令的一部分,例如 REQUEST_NEW_DATA
,这最终会触发名为 'new_data'
的 RPC。然而,REQUEST_REQUEST_NEW_DATA
是很愚蠢的。
CMD
也很尴尬,因为 REQUEST_SEND_NEW_DATA
会变成 CMD_SEND_NEW_DATA
,这有点尴尬。
有什么建议吗?
I'm using twisted. I have my protocols set up so that, to send an RPC, I do protocol.send("update_status", data)
. To document which RPCs I've implemented, I make a separate function call for each one, so in this case I'd call REQUEST_UPDATE_STATUS(data)
to send that RPC. When a protocol receives an RPC, a function gets called based on its name, in this case, CMD_UPDATE_STATUS
.
The problem is that REQUEST
and CMD
are a bit awkward. I can mistake REQUEST
as part of the command, for example, REQUEST_NEW_DATA
, and that would end up triggering an RPC called 'new_data'
. However, REQUEST_REQUEST_NEW_DATA
is just silly.
CMD
is also awkward, as a REQUEST_SEND_NEW_DATA
will become CMD_SEND_NEW_DATA
, which is a bit awkward.
Any tips?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个技巧:使用 PB...它设计精良,并且完全符合
第二个技巧:如果第一个技巧不适合您,只需执行 PB 的操作即可。在客户端,“callRemote(”foo_func”)”请求服务器调用服务器对象上的“foo_func”函数。然后,服务器将使用“getattr(server_obj, "remote_" + "foo_func")”来查找远程方法。如果该方法存在,则会调用该方法。否则返回错误。这种设计的好处是它完全消除了您的 REQUEST...CMD... 常量。
First tip: Use PB... it's well designed and does exactly that
Second Tip: If the first tip isn't going to work for you, just do what PB does. On the client end a "callRemote("foo_func")" asks the server ot invoke the "foo_func" function on the server object. The server will then use "getattr(server_obj, "remote_" + "foo_func")" to find the remote method. If the method exists, it's called. Otherwise an error is returned. The nice thing about this design is that it completely does away with your REQUEST... CMD... constants.