views:

164

answers:

1

Hi,

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

+1  A: 

To add an interactive console to your Twisted app, see this article -- it explains how to use twisted.internet.stdio for the purpose.

Alex Martelli
I followed this example initially but still do not quite understand what I need to do for my example.
J T
I'm not sure what else I can say besides copying the code from the example (the "good" version) at http://share11.appspot.com/1421 . Of course you'll always be processing the user-entered lines locally, just make some of the "verbs" cause a send-to-server (with callback etc); maybe you can use the standard library's `cmd` module to help. Show us (by editing your Q) as simple a version as you can of the code you've tried and isn't working and we may be able to offer specific suggestions, but right now I can't think of what it is that you may be doing wrong!
Alex Martelli