python扭曲stdio与服务器的多个连接,并带有命令提示符进行交互
我编写了一个简单的扭曲应用程序,它连接到侦听 1 个或多个端口的服务器。扭曲的应用程序连接到该服务器,通常一次连接到几个开放端口。该服务器是一个串行记录器,它连接到串行设备并通过原始 TCP 套接字提供串行线路信息,我需要将所有这些数据记录到磁盘。
我当前的应用程序将所有收到的信息记录到磁盘,没有问题。
我现在需要做但无法取得进展的是添加通过标准输入与我的应用程序交互的能力。我需要能够向本地应用程序发出命令,还需要通过连接的套接字发送文本命令。
我有一个使用 basic.LineReceiver 的基本提示并将其添加到我的反应器中,但无法弄清楚如何将数据发送到服务器,或者即使这是执行此操作的正确方法。
一个简化的例子将有助于展示我需要做什么。
谢谢杰
I have written a simple twisted application that connects to a server that listens on 1 or more ports. The twisted app connects to this server and usually connects to a few of the open ports at a time. This server is a serial logger that connects to serial devices and provides the serial line information through a raw TCP Socket and I need to log all this data to disk.
My current app logs any received information to disk without issue.
What I now need to do but am unable to make progress on is add the ability to interact with my application through stdin. I need to be able to issue commands to the local application but also send text commands through the connected sockets.
I have a basic prompt using basic.LineReceiver and adding this to my reactor but can't figure out how to send the data to the server or even if this is the correct way of doing this.
A simplified example would be helpful to show what I need to do.
Thanks
J
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要将交互式控制台添加到 Twisted 应用程序,请参阅本文 - 它解释了如何使用 twisted.internet.stdio 就是为了这个目的。
To add an interactive console to your Twisted app, see this article -- it explains how to use twisted.internet.stdio for the purpose.