Exemple #1
0
 def initialiseComponent(self):
     self.cat = coordinatingassistanttracker.getcat()
     self.isactivereceiver = False
     try:
         self.cat.registerService("streamingtextreceiver", self, "inbox")
     except ServiceAlreadyExists: # There is already a connected client sending data.
         self.send(socketShutdown(),"signal")
         return 0
     self.isactivereceiver = True
     # Find the splitter and passthrough link to it.
     self.splitter, self.splitterbox = self.cat.retrieveService("thesink")
     self.link((self, "inbox"),(self.splitter, self.splitterbox), passthrough=1)
               # inbox queue before shutting down the sending system.
         except Empty, e:
            pass # Normal case.
      
      #end while 1
      
      # After breaking out of while loop clean up socket before ending the thread.
      try:
         sock.shutdown(2)
      except socket.error, e:
         pass
      try:
         sock.close()
      except socket.error, e:
         self.outqueues["signal"].put(e)
      self.outqueues["signal"].put(socketShutdown())
      self.signalqueue.put("ThreadStopped")

if __name__ =="__main__":
   from Axon.Scheduler import scheduler
   from Kamaelia.SimpleServerComponent import SimpleServer
   from Kamaelia.Protocol.FortuneCookieProtocol import FortuneCookieProtocol
   from Kamaelia.Util.ConsoleEcho import  consoleEchoer
   # _tests()

   class testHarness(component): # Spike component to test interoperability with TCPServer
      def __init__(self):
         super(testHarness, self).__init__() # I wonder if this can get forced to be called automagically?
         import random
         self.serverport = random.randint(4000,8000)
         self.server = SimpleServer(protocol=FortuneCookieProtocol, port=self.serverport)