def __init__(self, nexusAddress, masterProtocol): self.nexusAddress = nexusAddress self.masterConnection = masterProtocol self.packet = Packet() self.emptyDict = { 'device': '%s', 'balanceUpdates': [], 'balance': 0}
class BackboneProtocol(protocol.Protocol): def __init__(self): self.packet = Packet() def sendData(self, data): self.transport.write(data) def dataReceived(self, data): parsedData = self.packet.parse(data, "") log.msg("received data: ", parsedData) def connectionMade(self): print "I am Nexus and connected to Backbone\n" a = Advert() self.sendData(a.buildPayload(12345, "localhost", 1, 2, 3, 4)) def connectionLost(self, reason): print "I am Nexus and have LOST connection to Backbone\n"
class BackboneProtocol(protocol.Protocol): def __init__(self): self.packet = Packet() def sendData(self, data): self.transport.write(data) def dataReceived(self, data): parsedData = self.packet.parse(data, "") log.msg("received data: ", parsedData) def connectionMade(self): print "I am Nexus and connected to Backbone\n" a = Advert() self.sendData(a.buildPayload(12345, "localhost",1,2,3,4)) def connectionLost(self, reason): print "I am Nexus and have LOST connection to Backbone\n"
class NexusTCPProtocol(Protocol): def __init__(self, nexusAddress, masterProtocol): self.nexusAddress = nexusAddress self.masterConnection = masterProtocol self.packet = Packet() self.emptyDict = { 'device': '%s', 'balanceUpdates': [], 'balance': 0} def sendData(self, data): self.transport.write(data) def forwardToMaster(self, data): self.masterConnection.sendData(data) def dataReceived(self, data): parsedData = self.packet.parse(data, self.nexusAddress) # since toJSON() sometimes returns a unicode string after sending # (no idea why...) we'll make sure it's encoded properly packetJson = parsedData.toJSON().encode('ascii','replace') log.msg("Received data from Nexus:", parsedData, "\n") self.forwardToMaster(packetJson) def connectionMade(self): log.msg("Connected to Nexus ", self.nexusAddress) # just in case the nexus missed it, re-send latest check try: checkDict = globalCheckDict[self.nexusAddress] except: log.err("No Checks available for this Nexus: ", self.nexusAddress) checkDict = self.emptyDict checkDeferred = threads.deferToThread(buildCheck, checkDict) checkDeferred.addCallback(self.sendData) def connectionLost(self, reason): log.msg("Connection to Nexus lost: ", self.nexusAddress, reason) self.transport.loseConnection()
class NexusTCPProtocol(Protocol): def __init__(self, nexusAddress, masterProtocol): self.nexusAddress = nexusAddress self.masterConnection = masterProtocol self.packet = Packet() self.emptyDict = {'device': '%s', 'balanceUpdates': [], 'balance': 0} def sendData(self, data): self.transport.write(data) def forwardToMaster(self, data): self.masterConnection.sendData(data) def dataReceived(self, data): parsedData = self.packet.parse(data, self.nexusAddress) # since toJSON() sometimes returns a unicode string after sending # (no idea why...) we'll make sure it's encoded properly packetJson = parsedData.toJSON().encode('ascii', 'replace') log.msg("Received data from Nexus:", parsedData, "\n") self.forwardToMaster(packetJson) def connectionMade(self): log.msg("Connected to Nexus ", self.nexusAddress) # just in case the nexus missed it, re-send latest check try: checkDict = globalCheckDict[self.nexusAddress] except: log.err("No Checks available for this Nexus: ", self.nexusAddress) checkDict = self.emptyDict checkDeferred = threads.deferToThread(buildCheck, checkDict) checkDeferred.addCallback(self.sendData) def connectionLost(self, reason): log.msg("Connection to Nexus lost: ", self.nexusAddress, reason) self.transport.loseConnection()
def __init__(self): self.packet = Packet()
def __init__(self): # self.masterConnection = masterProtocol self.packet = Packet()
def __init__(self, nexusAddress, masterProtocol): self.nexusAddress = nexusAddress self.masterConnection = masterProtocol self.packet = Packet() self.emptyDict = {'device': '%s', 'balanceUpdates': [], 'balance': 0}