示例#1
0
class ICUClient(protocol.ClientFactory):
    def __init__(self, reactor, ip=None, port=None, rcv_callback=None):
        self.reactor = reactor
        self.data_received = rcv_callback
        self.ip = ip if ip else 'localhost'
        self.port = port if port else 60000
        self.msg = None
        self.proto = None
        self.looping_func = None

    def buildProtocol(self, addr):
        if not self.proto:
            self.proto = ICUProtocol(self, self.clientReady,
                                     self.data_received)
        return self.proto

    def clientReady(self, proto):
        self.proto.sendLine(self.msg)
        self.proto.transport.loseConnection()

    def send_msg(self):
        self.connection = self.reactor.connectTCP(self.ip, self.port, self)

    def set_msg(self, msg):
        self.msg = msg

    def start_sending(self, time):
        self.looping_func = LoopingCall(self.send_msg)
        self.looping_func.start(time)

    def stop_sending(self):
        self.looping_func.stop()

    def clientConnectionFailed(self, connector, reason):
        pass

    def clientConnectionLost(self, connector, reason):
        pass
class ICUClient(protocol.ClientFactory):
	def __init__(self, reactor, ip=None, port=None, rcv_callback=None):
		self.reactor = reactor
		self.data_received = rcv_callback
		self.ip = ip if ip else 'localhost'
		self.port = port if port else 60000
		self.msg = None
		self.proto = None
		self.looping_func = None

	def buildProtocol(self, addr):
		if not self.proto:
			self.proto = ICUProtocol(self, self.clientReady, self.data_received)
		return self.proto

	def clientReady(self, proto):
		self.proto.sendLine(self.msg)
		self.proto.transport.loseConnection()

	def send_msg(self):
		self.connection = self.reactor.connectTCP(self.ip, self.port, self)

	def set_msg(self, msg):
		self.msg = msg

	def start_sending(self, time):
		self.looping_func = LoopingCall(self.send_msg)
		self.looping_func.start(time)
	
	def stop_sending(self):
		self.looping_func.stop()

	def clientConnectionFailed(self, connector, reason):
		pass
		
	def clientConnectionLost(self, connector, reason):
		pass
示例#3
0
	def buildProtocol(self, addr):
		self.proto = ICUProtocol(self, self.connection_success, self.rcv_callback)
		return self.proto
示例#4
0
 def buildProtocol(self, addr):
     if not self.proto:
         self.proto = ICUProtocol(self, self.clientReady,
                                  self.data_received)
     return self.proto
	def buildProtocol(self, addr):
		if not self.proto:
			self.proto = ICUProtocol(self, self.clientReady, self.data_received)
		return self.proto