[Twisted-Python] Interactive Twisted client (newbie question?)

Abe Fettig abe at fettig.net
Wed Jan 5 13:48:37 EST 2005


Anthony Tarlano wrote:

> From what I can tell from
> your post is you *really* want is a twisted styx client that sends
> T-messages to a styx server to serve its namespace with R-messages,
> and *you* want to interact with the client synchronously.. You also
> asked for a better way to implement the client not using callbacks,
> but that was not the real issue. For _you_ the real issue is
> synchronously communicating _with_the_styx_client from a command
> line..
> 
> If this assumption is correct then all you have to do is make the styx
> client a server as well, for let's say the telnet protocol. Then you
> can use a telnet client to connect to the telnet server (which is also
> the styx client) and bingo issue commands to the styx server (via the
> styx client that is also the telnet server)... Of course you will have
> to pass the styx server messages back to the telnet client

As JP mentioned, you can also use twisted.internet.stdio to provide a 
command line interface to your running Twisted application.  I'm 
attaching a simple app that illustrates the point.  Here's an example 
session:

$ python stdiodemo.py
Web checker console. Type 'help' for help.
help
Valid commands: check help quit
help check
check <url>: Attempt to download the given web page
check http://www.fettig.net/
Success: got 26072 bytes.
check http://www.fettig.net/nonexistant_page
Failure: 404 Not Found
check http://not.a.real.site/
Failure: DNS lookup failed: address 'not.a.real.site' not found.
quit
Goodbye.

stdiodemo.py takes commands from standard input while the reactor is 
running. When you type "check <url>", it kicks off an asyncronous task 
(downloading the web page), and prints the result when it is finished.

Anthony's suggestion of using a Telnet server could work here too - 
there are only a couple minor changes you'd need to make to run this as 
a telnet server.

Is that helpful?

Abe
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: stdiodemo.py
Url: http://twistedmatrix.com/pipermail/twisted-python/attachments/20050105/df154a08/attachment.txt 


More information about the Twisted-Python mailing list