[Twisted-Python] Interactive Twisted client (newbie question?)
Anthony Tarlano
mailinglist.account at gmail.com
Wed Jan 5 11:19:23 MST 2005
Hi Jon,
Interesting that you are implementing Styx with Twisted, I used to
work with Inferno and its father 9P (plan9) back during my Lucent
days.
Are you creating just creating a twisted Styx protocol client to use
with the vitanuova styx server or are you looking to do a server in
twisted as well? Let me know if you are redoing the styx server as
well in twisted, but back to your original problem question...
Keeping thing nice an simple, the pythonic way, I did a similar thing
in Twisted, but using a different method.. 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
Let me know if that answers you problem..
There is even an example in the howto's to setup both a client and
server from one factory
Cheers,
Anthony
On Mon, 3 Jan 2005 23:00:01 +0000, Jon Blower <jdb at mail.nerc-essc.ac.uk> wrote:
> Hi all,
>
> I'm new to Twisted, and I'm trying to create an implementation of a client
> program that communicates over a network with a server using a protocol called
> Styx. (In case you're interested, Styx is a protocol for distributed systems,
> as used by the Inferno operating system:
> http://www.vitanuova.com/inferno/papers/styx.html.) In short, Styx is a pretty
> simple call-response type of protocol, in which the client sends a T-message
> and waits for the corresponding R-message from the server. There is a
> one-to-one correspondence between T- and R-messages.
>
> I understand that Twisted is an event-driven framework and I have written a
> basic client program. My initial attempt has involved creating a StyxProtocol
> class that inherits from protocol.Protocol, in which I override key methods
> such as dataReceived() and connectionMade(). Having created this protocol and
> told it how to respond to messages that arrive, I created a simple Factory
> class, then set the whole thing running with reactor.run(). It works fine, but
> it's not quite in the form I'd like. In my current attempt, what I've done is
> essentially to create a load of callbacks and "press GO". Once I've set the
> program running I can't interact with it until one of the methods calls
> reactor.stop().
>
> What I'd like to be able to do is illustrated by the following pseudo-Python.
> This could be a script or could be typed into an interactive Python shell:
>
> conn = StyxConnection("myserver.remotehost.com", 6666)
> conn.connect() # Starts the reactor going and performs handshakes
> # The connection is now open and I can interact with it
> myRemoteFile = conn.openFile("/path/to/myfile") # Gets handle to file on remote
> server, by exchange of a few messages
> data = myRemoteFile.read() # Reads data from the remote file, again by exchange
> of some messages
> conn.close() # Closes the connection to the remote server and stops the reactor
>
> How can I do this with the Twisted framework? As far as I can tell,
> reactor.run() will not return until something calls reactor.stop(). I could
> achieve what I want using threads (I think), but I'd like to avoid this if
> possible.
>
> I'm sure I'm not the first to ask this sort of question, but I've looked through
> the docs and example code and haven't been able to track down an answer. I'd
> be very grateful for any pointers that anyone could offer.
>
> Regards,
> Jon
>
> --
> --------------------------------------------------------------
> Dr Jon Blower Tel: +44 118 378 5213 (direct line)
> Technical Director Tel: +44 118 378 8741 (ESSC)
> Reading e-Science Centre Fax: +44 118 378 6413
> ESSC Email: jdb at mail.nerc-essc.ac.uk
> University of Reading
> 3 Earley Gate
> Reading RG6 6AL, UK
> --------------------------------------------------------------
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
More information about the Twisted-Python
mailing list