由于发送小消息时的大延迟(大小 就个人而言,我会避免这样做,并尝试使用现有的,语言中立的通用编组层。 XML和ASN.1将是显而易见的,但我不建议使用其中任何一个,因为它们是可憎的。 JSON将是一个不错的选择: http://www.json。 org / 我也需要发送Python对象。它们过于精细,无法将它们转换为XML。 (他们使用循环弱引用和其他Python 特定的东西。)我可以肯定,在双方都有Python 程序。如果我已经需要发送 Python对象,那么使用XML有什么优势吗?这些对象不能用XML表示,除非将 腌制成CDATA字符串。 并没有太多的答案。有人确实指出了这一点,虽然: http://www.internet2.edu/~shalunov/w...ol-design.html Hmm ,这非常有帮助。谢谢! LesHello,I would like to develop a new network protocol, where the server and theclients are Python programs.I think to be effective, I need to use TCP_NODELAY, and manuallybuffered transfers.I would like to create a general messaging object that has methods likesendintegerrecvintegersendstringrecvstringTo be more secure, I think I can use this loads function to transfermore elaborate python stuctures:def loads(s):"""Loads an object from a string.@param s: The string to load the object from.@return: The object loaded from the string. This function will notunpickle globals and instances."""f = cStringIO.StringIO(s)p = cPickle.Unpickler(f)p.find_global = Nonereturn p.load()Am I on the right way to develop a new protocol?Are there any common mistakes that programmers do?Is there a howto where I can read more about this?ThanksLes 解决方案If you _must_ develop your own protocol, use at least twisted. But I''dgo for an existing solutions out there - namely pyro. No need to inventwheels again :)Regards,DiezNot really - protocol design is a bit of a black art. Someone asked aboutthis on comp.protocols.tcp-ip a while ago: http://groups.google.co.uk/group/com...ca111d67768b83And didn''t get much in the way of answers. Someone did point to this,though: http://www.internet2.edu/~shalunov/w...ol-design.htmlAlthough i don''t agree with much of what that says.tom--limited to concepts that are meta, generic, abstract and philosophical --IEEE SUO WGBecause of the big delays when sending small messages (size < 1500 bytes).Personally, i''d steer clear of doing it like this, and try to use anexisting, language-neutral generic marshalling layer. XML and ASN.1 wouldbe the obvious ones, but i wouldn''t advise using either of them, asthey''re abominations. JSON would be a good choice:http://www.json.org/I need to send Python objects too. They are too elaborate to convertthem to XML. (They are using cyclic weak references and other Pythonspecific stuff.) I can be sure that on both sides, there are Pythonprograms. Is there any advantage in using XML if I already need to sendPython objects? Those objects cannot be represented in XML, unlesspickled into a CDATA string.And didn''t get much in the way of answers. Someone did point to this,though:http://www.internet2.edu/~shalunov/w...ol-design.htmlHmm, this was very helpful. Thank you!Les 这篇关于使用Python开发网络协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-03 14:54