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

Jon Blower jdb at mail.nerc-essc.ac.uk
Mon Jan 10 08:50:51 EST 2005

Hi all,

Thanks for everyone who replied with help on this issue.  After much
head-scratching I decided that Twisted was not the right framework for my
particular app and I solved my problem another way.  The idea of running a
Twisted app with a Telnet or stdio interface is a great idea though; I'll
bear this in mind for the future.

In case anyone's interested, the approach I took (for implementing a client
program that speaks the Styx protocol) was to create a client class that
implements a sendMessage() method.  When the client class connects to the
remote server, it fires off a background thread that continually listens for
received messages, firing an event when a whole message arrives.  A user can
send a message, then wait for the corresponding reply, or the user can send
a message and arrange for a callback method to be called when the reply
arrives.  (in Styx, a user can send several messages without waiting for
replies)  This allows both synchronous and asynchronous approaches and means
that I can use the client classes at the Python prompt, e.g:

from styx import *
conn = StyxConnection("aserver.com", 6666) # connect to the server
f = conn.open("afile", "r") # open a file for reading
f.read() # read the contents of the file

(In Styx, all remote resources are virtualised as files, so you interact
with a remote resource by reading from and writing to file-like objects.)

Thanks again,

-----Original Message-----
From: twisted-python-bounces at twistedmatrix.com
[mailto:twisted-python-bounces at twistedmatrix.com]On Behalf Of Andrew
Sent: 06 January 2005 00:35
To: Twisted general discussion
Subject: Re: [Twisted-Python] Interactive Twisted client (newbie

On Wed, Jan 05, 2005 at 01:48:37PM -0500, Abe Fettig wrote:
> 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:

Nice example of stdio, LineReceived, and using deferreds!  Abe, can we
include this example in Twisted?


Twisted-Python mailing list
Twisted-Python at twistedmatrix.com

More information about the Twisted-Python mailing list