扭曲的传输.write

发布于 2024-09-17 03:26:55 字数 517 浏览 3 评论 0原文

有没有办法强制 self.transport.write(response) 立即写入其连接,以便下一次调用 self.transport.write(response) 不会缓冲到同一个调用中。

我们有一个客户,其遗留软件无法修改,它读取第一个请求,然后再次开始读取,我遇到的问题是扭曲地将两个写入连接在一起,这打破了客户我尝试过延迟的任何想法,但我不知道我认为在这种情况下不会有帮助

示例:

self.transport.write("|123|") # amount of messages to follow 
a loop to generate next message
self.transport.write("|message 1 text here|")

预期:

|123|
|message 1 text here|

结果:

|123||message 1 text here|

Is there any way to force self.transport.write(response) to write immediately to its connection so that the next call to self.transport.write(response) does not get buffered into the same call.

We have a client with legacy software we cannot amend, that reads for the 1st request and then starts reading again, and the problem I have is twisted joins the two writes together which breaks the client any ideas i have tried looking into deferreds but i don't think it will help in this case

Example:

self.transport.write("|123|") # amount of messages to follow 
a loop to generate next message
self.transport.write("|message 1 text here|")

Expected:

|123|
|message 1 text here|

Result:

|123||message 1 text here|

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

近箐 2024-09-24 03:41:12

也许您可以将协议注册为传输的拉生产者

self.transport.registerProducer(self, False)

,然后在协议中创建一个具有作业缓冲的写入方法
数据,直到传输调用协议的resumeProducing方法来获取
数据一一列出。

def write(self, data):
    self._buffers.append(data)

def resumeProducing(self):
    data = self._buffers.pop()
    self.transport.write(data)

Maybe You can register your protocol as a pull producer to the transport

self.transport.registerProducer(self, False)

and then create a write method in your protocol that has it's job buffering
the data until the transport call your protocol resumeProducing method to fetch
the data one by one.

def write(self, data):
    self._buffers.append(data)

def resumeProducing(self):
    data = self._buffers.pop()
    self.transport.write(data)
淡水深流 2024-09-24 03:38:37

您能告诉我您使用的是哪种交通工具吗?对于大多数实现来说,
这是典型的方法:

 def write(self, data):
        if data:
            if self.writeInProgress:
                self.outQueue.append(data)
            else:
                ....

根据详细信息,可以更改写入函数的行为以根据需要进行操作。

Can you tell which transport you are using. For most implementations,
This is the typical approach :

 def write(self, data):
        if data:
            if self.writeInProgress:
                self.outQueue.append(data)
            else:
                ....

Based on the details the behavior of write function can be changed to do as desired.

枫以 2024-09-24 03:35:59

我在使用低级 Python 2.6 时遇到了一些相关的问题。与我交谈的主机期待一个 ACK​​ 字符,然后是一个单独的数据缓冲区,它们全部同时出现。在上面
其中,这是一个 TLS 连接。但是,如果您直接引用套接字,则可以调用
sendall() as:

self.transport.write(Global.ACK)

to:

self.transport.getHandle().sendall(Global.ACK)

... 这应该有效。这在 X86 上使用 Twisted 的 Python 2.7 上似乎不是问题,只是
SHEEVAPlug ARM 处理器上的 Python 2.6。

I was having a somewhat related problem using down level Python 2.6. The host I was talking to was expecting a single ACK character, and THEN a separate data buffer, and they all came at once. On top
of this, it was a TLS connection. However, if you reference the socket DIRECTLY, you can invoke a
sendall() as:

self.transport.write(Global.ACK)

to:

self.transport.getHandle().sendall(Global.ACK)

... and that should work. This does not seem to be a problem on Python 2.7 with Twisted on X86, just
Python 2.6 on a SHEEVAPlug ARM processor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文