I'm writing a small script to record an MP3 stream. It connects to a remote host and accepts start/stop commands to control the recording. Everything's working, except I can't figure out how to stop the HTTPDownloader. When I try to close the HTTP download connection (line 22, below), self.stream_factory.protocol (which is an HTTPPageDownloader) has a None transport member. Am I going about this the right way? john 01 def start_stream_download(url): 02 scheme, host, port, path = client._parse(url) 03 factory = client.HTTPDownloader(url, 'foo.mp3') 04 reactor.connectTCP(host, port, factory) 05 return factory 06 07 class GpioClient(protocol.Protocol): 08 stream_factory = None 09 10 def connectionMade(self): 11 self.transport.write('ADD GPO\n') 12 13 def dataReceived(self, data): 14 data = data.rstrip() 15 if re.match(r'^GPO %d [lL]' % GPO_CHANNEL, data): 16 if self.stream_factory: 17 self.stream_factory.protocol.transport.loseConnection() 18 self.stream_factory = start_stream_download(STREAM_URL) 19 elif re.match(r'^GPO %d [hH]' % GPO_CHANNEL, data): 20 if self.stream_factory: 21 # Stop recording. 22 self.stream_factory.protocol.transport.loseConnection() 23 self.stream_factory = None -- John Morrissey _o /\ ---- __o jwm@horde.net _-< \_ / \ ---- < \, www.horde.net/ __(_)/_(_)________/ \_______(_) /_(_)__
participants (2)
-
Jean-Paul Calderone
-
John Morrissey