扭曲>如何从窗口 TCP 客户端读取长于 TCP 帧长度(例如 1380 字节)的 TCP 消息
我正在编写一个扭曲的服务器来读取最大 64KB 的 TCP 消息。我发现 mt datareciever 被 linereciever 类每 1380 字节调用一次,结果是 Windows 客户端的 TCP 帧大小。有没有办法解决这个问题,而不必循环遍历这些 1380 字节块?
from twisted.internet.protocol import Protocol
from twisted.internet.protocol import Factory
from twisted.enterprise.adbapi import ConnectionPool
class CSVReceiver(Protocol):
def dataReceived(self, line):
print 'line RX :', len(line) , ' : ' , str(line)
dataReceived 被调用并每 1380 字节打印一次,例如,当 6KB 的 TCP 消息发送到我们的服务器时,打印 4X。有什么方法可以避免这种情况,以便我们可以在一次回调中处理整个字符串?
谢谢。
斯坦
I am writing a twisted server to read TCP messages up to 64KB. What I discovered was that mt datareciever was called by the linereciever class every 1380 bytes, which turned out to be the Windows client's TCP frame size. Is there a way to get around this without having to loop through these 1380 byte blocks?
from twisted.internet.protocol import Protocol
from twisted.internet.protocol import Factory
from twisted.enterprise.adbapi import ConnectionPool
class CSVReceiver(Protocol):
def dataReceived(self, line):
print 'line RX :', len(line) , ' : ' , str(line)
The dataReceived gets called and prints every 1380 bytes, e.g. 4X when a TCP message of 6KB is sent to our server. Any method to avoid this so we can process the entire string in one call-back?
Thank you.
STAN
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你在 python_forum 上问了这个问题,我在那里回答了你。您想要使用 LineReciever,并且想要将 MAX_LENGTH 设置为更大的数字。
You asked this question on the python_forum, I answered you there. You want to be using LineReciever, and you want to set
MAX_LENGTH
to a higher number.TCP 发送数据流,而不是消息。中间网络可能会将您的流分成任意小块以进行传输。如果您可以控制发生此情况的整个网络,您可以 调整您的 Windows 客户端以具有不同的窗口大小。但是,您可能还需要专门配置本地路由器以支持 巨型帧,因为即使是以太网也支持默认情况下不支持大于 1500 个八位字节的帧。
基本上,对于任何网络(除了最简单的例子之外),您的问题的答案都是“否”。但是,你为什么要关心这个呢?
LineReceiver
存在的目的是向您提供整行数据,而您不必担心来自 TCP 流的各个任意大小的数据块。TCP sends streams of data, not messages. The intermediary network may break your streams up into arbitrarily small chunks for transport. If you have control over the entire network where this is occurring, you can tune your Windows clients to have a different window size. But then you may also have to specially configure your local router to support Jumbo frames, since even Ethernet does not support frames of greater than 1500 octets by default.
Basically, for any network but the most trivial example, the answer to your question is "no". But, why would you care about this? The whole reason that
LineReceiver
exists is to deliver whole lines to you, rather than you having to worry about individual arbitrarily-sized chunks of data coming off a TCP stream.