Twisted Python:最大数据包大小?冲水插座?
我正在为服务器端实现一个基于 Twisted 的客户端-服务器解决方案,并为客户端实现一个基于 Android 手机的客户端-服务器解决方案。 因为 Andoird 模拟器不接受大于 1500b(或更少?)的 TCP 数据包,所以我需要能够在服务器端对数据包进行分块。在每次“transport.write”之后不刷新套接字,Twisted 会缓冲传出数据,因此如果没有某种手动或自动刷新/ maxpacketsize 功能,分块将毫无用处。我如何在 Twisted 中执行此操作? 我熟悉“reactor.doSelect(1)”函数,但由于我使用的是 EPoll 反应器(出于可扩展性和性能原因),我无法使用 doSelect。是否可以更改 Twisted 中某些连接的 maxPacketValue?
希望有人能给我带来光明...
I'm implementing a client-server solution based on Twisted for the server side and e.g. and Android phone for the client side.
Because the Andoird emulator takes no TCP Packets larger then 1500b (or less?), I need to be able to chunk packets on the server side. Without flushing the socket after each "transport.write", Twisted buffers the outgoing data so the chunking would be useless without somekind of manual or automatic flushing / maxpacketsize function. How do I do this in Twisted?
I'm familiar with the "reactor.doSelect(1)" function, but since I'm using the EPoll reactor (for scalability and performance reasons), I cannot use doSelect. Is it possible to change the maxPacketValue for certain connections within Twisted?
Hoping that someone can show me the light...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TCP 数据包由操作系统自动分块,应用程序所能做的就是给出何时刷新的提示。除此之外,应用程序只能读取和写入流。
两个通信对等体的操作系统将根据路径 MTU 发现<的链路上的 MTU 自动配置最大数据包大小/a>.确保您没有阻止 ICMP 数据包才能使其正常工作。
由于问题极不可能是错误的 MTU(并且通常会设置 1500 或更低的 MTU),因此您应该重新诊断您的问题,例如使用数据包跟踪器,例如 wireshark。
TCP packets are automatically chunked by the OS, all the application can do is give hints when to flush. Apart from that, an application can just read and write to a stream.
The OSs of two communicating peers will automatically configure the maximum packet sizes based on the MTU on the links with Path MTU discovery. Make sure you don't block ICMP packets to get that to work.
Since it is extremely unlikely that a wrong MTU is the problem (and an MTU of 1500 or less is often set anyway), you should re-diagnose your problem, for example with a packet tracer such as wireshark.
TCP是面向流的协议,而不是面向数据包的协议。当您调用
transport.write
时,该数据将被附加到 TCP 流中,并且可以以任意数量的数据包发送出去;它可能会被分解,或者与下一个或上一个对write
的调用粘合在一起。这是一个相当关于 Twisted 的常见问题,但是每个提出这个问题的人询问的方式略有不同。您想要使用协议构建工具包,例如 AMP,或者,更基本的是, LineReceiver在协议中定界消息,而不是依赖数据包边界的随机性质。
TCP is a stream-oriented protocol, not a packet-oriented protocol. When you call
transport.write
, that data gets appended to the TCP stream and may be sent out in any number of packets; it might be broken up, or glued together with the next or previous call towrite
. This is a fairly frequently asked question about Twisted, but everyone who asks it asks it slightly differently.You want to use a protocol construction kit like AMP, or, more basically, LineReceiver, to delimit the messages within your protocol, rather than relying upon the random nature of packet boundaries.