简体   繁体   English

最佳Python支持的服务器/客户端协议?

[英]Best Python supported server/client protocol?

I'm looking for a good server/client protocol supported in Python for making data requests/file transfers between one server and many clients. 我正在寻找一个支持Python的良好服务器/客户端协议,用于在一个服务器和许多客户端之间进行数据请求/文件传输。 Security is also an issue - so secure login would be a plus. 安全性也是一个问题 - 因此安全登录将是一个优势。 I've been looking into XML-RPC, but it looks to be a pretty old (and possibly unused these days?) protocol. 我一直在研究XML-RPC,但它看起来是一个非常古老的(现在可能还没用?)协议。

If you are looking to do file transfers, XMLRPC is likely a bad choice. 如果您希望进行文件传输,XMLRPC可能是一个糟糕的选择。 It will require that you encode all of your data as XML (and load it into memory). 它需要您将所有数据编码为XML(并将其加载到内存中)。

"Data requests" and "file transfers" sounds a lot like plain old HTTP to me, but your statement of the problem doesn't make your requirements clear. “数据请求”和“文件传输”对我来说听起来很像普通的旧HTTP,但是您对问题的陈述并未使您的要求明确。 What kind of information needs to be encoded in the request? 需要在请求中编码哪种信息? Would a URL like " http://yourserver.example.com/service/request?color=yellow&flavor=banana " be good enough? 像“ http://yourserver.example.com/service/request?color=yellow&flavor=banana ”这样的网址是否足够好?

There are lots of HTTP clients and servers in Python, none of which are especially great, but all of which I'm sure will get the job done for basic file transfers. Python中有很多HTTP客户端和服务器,其中没有一个特别好,但我确信所有这些都将完成基本文件传输的工作。 You can do security the "normal" web way, which is to use HTTPS and passwords, which will probably be sufficient. 您可以使用“正常”Web方式执行安全性,即使用HTTPS和密码,这可能就足够了。

If you want two-way communication then HTTP falls down, and a protocol like Twisted's perspective broker (PB) or asynchronous messaging protocol (AMP) might suit you better. 如果你想要双向通信,那么HTTP就会崩溃,像Twisted的透视代理(PB)异步消息协议(AMP)这样的协议可能会更适合你。 These protocols are certainly well-supported by Twisted. Twisted肯定很好地支持这些协议。

ProtocolBuffers was released by Google as a way of serializing data in a very compact efficient way. Google发布了ProtocolBuffers ,作为一种以非常紧凑的高效方式序列化数据的方式。 They have support for C++, Java and Python. 他们支持C ++,Java和Python。 I haven't used it yet, but looking at the source, there seem to be RPC clients and servers for each language. 我还没有使用它,但从源头看,似乎每种语言都有RPC客户端和服务器。

I personally have used XML-RPC on several projects, and it always did exactly what I was hoping for. 我个人在几个项目中使用过XML-RPC,它总是完全按照我的意愿行事。 I was usually going between C++, Java and Python. 我通常介于C ++,Java和Python之间。 I use libxmlrpc in Python often because it's easy to memorize and type interactively, but it is actually much slower than the alternative pyxmlrpc . 我经常在Python中使用libxmlrpc,因为它易于记忆和交互式输入,但它实际上比替代pyxmlrpc慢得多。

PyAMF is mostly for RPC with Flash clients, but it's a compact RPC format worth looking at too. PyAMF主要用于带有Flash客户端的RPC,但它也是一种值得关注的紧凑型RPC格式。

When you have Python on both ends, I don't believe anything beats Pyro (Python Remote Objects.) Pyro even has a "name server" that lets services announce their availability to a network. 当你的两端都有Python时,我不相信Pyro (Python远程对象).Pyro甚至还有一个“名称服务器”,可以让服务宣布它们可用于网络。 Clients use the name server to find the services it needs no matter where they're active at a particular moment. 客户端使用名称服务器来查找它所需的服务,无论它们在特定时刻处于何种活动状态。 This gives you free redundancy, and the ability to move services from one machine to another without any downtime. 这为您提供了免费冗余,并且能够在不停机的情况下将服务从一台机器移动到另一台机器。

For security, I'd tunnel over SSH, or use TLS or SSL at the connection level. 为了安全起见,我通过SSH进行隧道传输,或者在连接级别使用TLS或SSL。 Of course, all these options are essentially the same, they just have various difficulties of setup. 当然,所有这些选项基本相同,它们只有各种设置难度。

Pyro (Python Remote Objects) is fairly clever if all your server/clients are going to be in Python. 如果所有服务器/客户端都在Python中, Pyro (Python远程对象)相当聪明。 I use XMPP alot though since I'm communicating with hosts that are not always Python. 我使用XMPP很多,因为我正在与不总是Python的主机通信。 XMPP lends itself to being extended fairly easily too. XMPP也很容易扩展。

There is an excellent XMPP library for python called PyXMPP which is reasonably up to date and has no dependancy on Twisted. 有一个优秀的python XMPP库,名为PyXMPP ,它是合理的最新版本,不依赖于Twisted。

I suggest you look at 1. XMLRPC 2. JSONRPC 3. SOAP 4. REST/ATOM XMLRPC is a valid choice. 我建议你看看1. XMLRPC 2. JSONRPC 3. SOAP 4. REST / ATOM XMLRPC是一个有效的选择。 Don't worry it is too old. 别担心它太老了。 That is not a problem. 那不是问题。 It is so simple that little needed changing since original specification. 它非常简单,从原始规格开始就很少需要改变。 The pro is that in every programming langauge I know there is a library for a client to be written in. Certainly for python. 专业人士认为,在每个编程方法中,我都知道有一个用于编写客户端的库。当然对于python。 I made it work with mod_python and had no problem at all. 我使用mod_python工作,完全没有问题。 The big problem with it is its verbosity. 最大的问题是它的冗长。 For simple values there is a lot of XML overhead. 对于简单值,存在大量的XML开销。 You can gzip it of cause, but then you loose some debugging ability with the tools like Fiddler. 你可以解压缩它的原因,但是你用Fiddler这样的工具就失去了一些调试能力。

My personal preference is JSONRPC. 我个人的偏好是JSONRPC。 It has all of the XMLRPC advantages and it is very compact. 它具有XMLRPC的所有优点,而且非常紧凑。 Further, Javascript clients can "eval" it so no parsing is necessary. 此外,Javascript客户端可以“评估”它,因此不需要解析。 Most of them are built for version 1.0 of the standard. 其中大多数都是为1.0版标准构建的。 I have seen diverse attempts to improve on it, called 1.1 1.2 and 2.0 but they are not built one on top of another and, to my knowledge, are not widely supported yet. 我已经看到了不同的尝试来改进它,称为1.1 1.2和2.0,但它们不是一个在另一个之上构建的,据我所知,它还没有被广泛支持。 2.0 looks the best, but I would still stick with 1.0 for now (October 2008) 2.0看起来最好,但我现在仍然坚持1.0(2008年10月)

Third candidate would be REST/ATOM. 第三位候选人将是REST / ATOM。 REST is a principle, and ATOM is how you convey bulk of data when it needs to for POST, PUT requests and GET responses. REST是一个原则,ATOM是在需要POST,PUT请求和GET响应时传送大量数据的方式。 For a very nice implementation of it, look at GData, Google's API. 有关它的非常好的实现,请查看GData,Google的API。 Real real nice. 真的很好。

SOAP is old, and lots lots of libraries / langauges support it. SOAP很老,很多库/语言都支持它。 IT is heeavy and complicated, but if your primary clients are .NET or Java, it might be worth the bother. 它非常复杂,但如果您的主要客户端是.NET或Java,那么可能值得一试。 Visual Studio would import your WSDL file and create a wrapper and to C# programmer it would look like local assembly indeed. Visual Studio将导入您的WSDL文件并创建一个包装器,而对于C#程序员来说,它看起来确实像本地程序集。

The nice thing about all this, is that if you architect your solution right, existing libraries for Python would allow you support more then one with almost no overhead. 关于这一切的好处是,如果你正确构建你的解决方案,Python的现有库将允许你支持多一个几乎没有开销。 XMLRPC and JSONRPC are especially good match. XMLRPC和JSONRPC特别匹配。

Regarding authentication. 关于认证。 XMLRPC and JSONRPC don't bother defining one. XMLRPC和JSONRPC不打算定义一个。 It is independent thing from the serialization. 它与序列化是独立的。 So you can implement Basic Authentication, Digest Authentication or your own with any of those. 因此,您可以实现基本身份验证,摘要身份验证或您自己的身份验证。 I have seen couple of examples of client side Digest Authentication for python, but am yet to see the server based one. 我已经看到了几个用于python的客户端摘要式身份验证示例,但我还没有看到基于服务器的服务器。 If you use Apache, you might not need one, using mod_auth_digest Apache module instead. 如果您使用Apache,则可能不需要使用Apache,而是使用mod_auth_digest Apache模块。 This depens on the nature of your application 这取决于您的应用程序的性质

Transport security. 运输安全。 It is obvously SSL (HTTPS). 它显然是SSL(HTTPS)。 I can't currently remember how XMLRPC deals with, but with JSONRPC implementation that I have it is trivial - you merely change http to https in your URLs to JSONRPC and it shall be going over SSL enabled transport. 我目前还不记得XMLRPC是如何处理的,但是对于我所拥有的JSONRPC实现来说这很简单 - 您只需将URL中的http更改为JSONRPC中的https,它就应该通过启用SSL的传输。

HTTP seems to suit your requirements and is very well supported in Python. HTTP似乎符合您的要求,并且在Python中得到了很好的支持。

Twisted is good for serious asynchronous network programming in Python, but it has a steep learning curve, so it might be worth using something simpler unless you know your system will need to handle a lot of concurrency. Twisted适用于Python中严格的异步网络编程,但它有一个陡峭的学习曲线,所以除非你知道你的系统需要处理大量并发,否则它可能值得使用更简单的东西。

To start, I would suggest using urllib for the client and a WSGI service behind Apache for the server. 首先,我建议为客户端使用urllib ,为服务器使用Apache背后WSGI服务 Apache can be set up to deal with HTTPS fairly simply. Apache可以设置为相当简单地处理HTTPS。

SSH can be a good choice for file transfer and remote control, especially if you are concerned with secure login. SSH可以是文件传输和远程控制的理想选择,尤其是在您关注安全登录时。 Most Linux and Solaris servers will already run an SSH service for administration, so if your Python program use ssh then you don't need to open up any additional ports or services on remote machines. 大多数Linux和Solaris服务器已经运行SSH服务进行管理,因此如果您的Python程序使用ssh,则无需在远程计算机上打开任何其他端口或服务。

OpenSSH is the standard and portable SSH client and server, and can be used via subprocesses from Python. OpenSSH是标准的可移植SSH客户端和服务器,可以通过Python的子进程使用。 If you want more flexibility Twisted includes Twisted Conch which is a SSH client and server implementation which provides flexible programmable control of an SSH stack, on both Linux and Windows. 如果您想要更高的灵活性,Twisted包括Twisted Conch ,这是一个SSH客户端和服务器实现,可在Linux和Windows上提供灵活的SSH堆栈可编程控制。 I use both in production. 我在生产中都使用它们。

There is no need to use HTTP (indeed, HTTP is not good for RPC in general in some respects), and no need to use a standards-based protocol if you're talking about a python client talking to a python server. 没有必要使用HTTP(实际上,在某些方面,HTTP通常不利于RPC),如果您正在谈论与python服务器通信的python客户端,则无需使用基于标准的协议。

Use a Python-specific RPC library such as Pyro, or what Twisted provides (Twisted.spread). 使用特定于Python的RPC库(如Pyro)或Twisted提供的(Twisted.spread)。

I'd use http and start with understanding what the Python library offers. 我使用http并开始理解Python 提供的内容。

Then I'd move onto the more industrial strength Twisted library. 然后我将进入更具工业实力的Twisted库。

Facebook's thrift project may be a good answer. Facebook的节俭项目可能是一个很好的答案。 It uses a light-weight protocol to pass object around and allows you to use any language you wish. 它使用轻量级协议传递对象,并允许您使用任何您想要的语言。 It may fall-down on security though as I believe there is none. 它可能会降低安全性,但我相信没有。

XMLRPC is very simple to get started with, and at my previous job, we used it extensively for intra-node communication in a distributed system. XMLRPC非常简单,在我以前的工作中,我们广泛用于分布式系统中的节点内通信。 As long as you keep track of the fact that the None value can't be easily transferred, it's dead easy to work with, and included in Python's standard library. 只要您跟踪无法轻松传输None值的事实,它就很容易使用,并且包含在Python的标准库中。

Run it over https and add a username/password parameter to all calls, and you'll have simple security in place. 通过https运行并为所有呼叫添加用户名/密码参数,您将拥有简单的安全性。 Not sure about how easy it is to verify server certificate in Python, though. 但不确定在Python中验证服务器证书是多么容易。

However, if you are transferring large amounts of data, the coding into XML might become a bottleneck, so using a REST -inspired architecture over https may be as good as xmlrpclib. 但是,如果要传输大量数据,则编码为XML可能会成为瓶颈,因此在https上使用REST启发的体系结构可能与xmlrpclib一样好。

在RPC字段中,Json-RPC将比xml-rpc带来更大的性能提升: http//json-rpc.org/wiki/python-json-rpc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python套接字服务器/客户端协议与不稳定的客户端连接 - python socket server/client protocol with unstable client connection python raw socket:不支持协议 - python raw socket: Protocol not supported 在与python的客户端 - 服务器应用程序通信中使用什么协议? - What protocol to use in client-server app communication with python? 将协议缓冲区编码的消息从 Python 服务器发送到 Java 客户端 - Sending Protocol Buffer encoded message from Python Server to Java Client 如何最好地在python中实现服务器和客户端? - How to best implement server and client in python? libcurl ubuntu python中不支持或禁用协议“https” - Protocol "https" not supported or disabled in libcurl ubuntu python Python SMTP 服务器协议 - Python SMTP Server protocol 在 Python 中使用 MySQL 连接器出现“客户端不支持服务器请求的身份验证协议”的错误 - Getting an error of "Client does not support authentication protocol requested by server" using MySQL Connector in Python 如何使用python使用OPC UA协议从服务器与客户端进行通信 - how to communicate from a server to client using OPC UA protocol using python 简单的服务器/客户端字符串交换协议 - Simple server/client string exchange protocol
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM