Twisted transport.write

牧云@^-^@ 提交于 2019-12-01 18:54:28

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.

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.

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)

Put a relatively large delay (10 seconds) between writes. This will be the only possible solution. Because if the recipient is so badly written by people who don't know what TCP is and how to use it, you can hardly do anything (other than rewrite that application).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!