[Twisted-Python] closing udp client?

p@ digi at treepy.com
Wed May 14 00:57:40 EDT 2003


I have the following protocol for a udp client:
 
class UdpClientProtocol (ConnectedDatagramProtocol):
    def __init__(self,request=None):
        self.request = request
    def startProtocol(self):
        self.transport.write(self.request)
    def datagramReceived(self,answer,address):
        print 'datagram recieved:'
        print data
        print 'from:',address
 
I want to send a udp packet and then wait for the answer. but what if
there is no answer? So I need a timeout client...
 
I tried it with:
 
class UdpClientProtocol (ConnectedDatagramProtocol):
    def __init__(self,request=None):
        self.request = request
        reactor.callLater(5, self.timeout())
    def startProtocol(self):
        self.transport.write(self.request)
    def datagramReceived(self,answer,address):
        print 'datagram recieved:'
        print data
        print 'from:',address
    def timeout(self):
        print 'timeout'
 
this works. but if I try to close this protocol after 5 seconds with
self.transport.loseConnection() I get an exception..
So my actuall question is: how to close this port/protocol/factory
again?
 
Cheers
 
p@
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20030514/d727c3aa/attachment.htm 


More information about the Twisted-Python mailing list