[Twisted-Python] (Un)Twisted Clients and Servers (newbie)

Bill la Forge laforge49 at yahoo.co.in
Wed May 26 23:38:05 MDT 2004


Bob Ippolito wrote:
> As far as switching between "async" and 'blocking",
> why don't you just yield BlockingMode and yield 
> AsyncMode?

Well, I'm doing something like that now. Here's my
updated client protocol. Now at least you don't need
to remember what to yield (a potential source of 
errors). Plus you save a few lines. Thanks for the 
suggestion.

class SCP(CSProtocol):
    """
    Simple Client Protocol
    """
    def cs(self):
        lf=LineFilter()
        lf.delimiter=chr(26)
        pushFilter(self,0,lf)
        inp=self.device[0]
        out=self.device[1]
        while True:
            yield inp.startRead()
            try:
                data=inp.endRead()
            except:
                break
            if data=='exit':
                break
            yield self.blockingIOMode()
            sys.stdout.write(data)
            txt=sys.stdin.readline()
            yield self.asyncIOMode()
            if not len(txt):
                break
            yield out.startWrite(txt)
            try:
                out.endWrite()
            except:
                break
        closeDevices(self)
        reactor.stop()


=====
Bill la Forge
http://www.geocities.com/laforge49/

________________________________________________________________________
Yahoo! India Matrimony: Find your partner online. http://yahoo.shaadi.com/india-matrimony/




More information about the Twisted-Python mailing list