扭曲传输.write [英] Twisted transport.write

查看:31
本文介绍了扭曲传输.write的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

示例:

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|

推荐答案

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

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)

到:

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

...这应该可以工作.这在 Python 2.7 和 X86 上的 Twisted 上似乎不是问题,只是SHEEVAPlug ARM 处理器上的 Python 2.6.

... 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.

这篇关于扭曲传输.write的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆