thanks jean-Pul.i can use commandline to intercat with server by the StandardIO.<br>it's so easy with it <br><br>and there is a sample in Twisted NetWork Programming Essentials<br><br>wow<br><br>from twisted.internet import stdio, reactor, protocol
<br>from twisted.protocols import basic
<br>import re
<br>
<br>class DataForwardingProtocol(protocol.Protocol):
<br> def _ _init_ _(self):
<br> self.output = None
<br> self.normalizeNewlines = False
<br>
<br> def dataReceived(self, data):
<br> if self.normalizeNewlines:
<br> data = re.sub(r"(\r\n|\n)", "\r\n", data)
<br> if self.output:
<br> self.output.write(data)
<br>
<br>class StdioProxyProtocol(DataForwardingProtocol):
<br> def connectionMade(self):
<br> inputForwarder = DataForwardingProtocol( )
<br> inputForwarder.output = self.transport
<br> inputForwarder.normalizeNewlines = True
<br> stdioWrapper = stdio.StandardIO(inputForwarder)
<br> self.output = stdioWrapper
<br> print "Connected to server. Press ctrl-C to close connection."
<br>
<br>class StdioProxyFactory(protocol.ClientFactory):
<br> protocol = StdioProxyProtocol
<br>
<br> def clientConnectionLost(self, transport, reason):
<br> reactor.stop( )
<br>
<br> def clientConnectionFailed(self, transport, reason):
<br> print reason.getErrorMessage( )
<br> reactor.stop( )
<br>
<br>if __name__ == '_ _main_ _':
<br> import sys
<br> if not len(sys.argv) == 3:
<br> print "Usage: %s host port" % _ _file_ _
<br> sys.exit(1)
<br>
<br> reactor.connectTCP(sys.argv[1], int(sys.argv[2]), StdioProxyFactory( ))
<br> reactor.run( )
<br><br><br><br><br><div class="gmail_quote">On Tue, Dec 2, 2008 at 10:11 PM, Jean-Paul Calderone <span dir="ltr"><<a href="mailto:exarkun@divmod.com">exarkun@divmod.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="Wj3C7c">On Tue, 2 Dec 2008 21:38:18 +0800, lei ren <<a href="mailto:reynold.lei@gmail.com" target="_blank">reynold.lei@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
hello ,everybody:<br>
i am a new to use the twisted. i woul'd like to complete a WEBGAME with<br>
it.but i have a problem for the twisted<br>
i have complete the server ,and the simple client.but ,i want to the client<br>
have more function. one is let the usr input some command to the server<br>
but when i write the code ,i found it's hard ,if i want to get the user's<br>
input with raw_input() in a while loop,but it will block to wait the user'<br>
input<br>
what can i do for this .use thread? of twisted have some more power feature<br>
for the problem,,thank you every body<br>
<br>
ps:the problem like a MUD game ,user can send the command to the server and<br>
reveive the message from server .and the user can send command everytime<br>
<br>
</blockquote>
<br></div></div>
The way to read from stdin without blocking the reactor is to use<br>
twisted.internet.stdio.StandardIO, a transport which lets a protocol<br>
interact with standard in and standard out.<br><font color="#888888">
<br>
Jean-Paul</font><div><div></div><div class="Wj3C7c"><br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</div></div></blockquote></div><br>