def open(self, *args): with self.lock: try: args = args[0].split("/") id = int(args[0]) if len(args) > 1: self.isBackground = True except: id = None connections = self._commHandler.connections if connections.has_key(id): isConnectedABackground = connections[id].client.isBackground if isConnectedABackground: background = connections.pop(id) background.ID = str(id) + "_background" connections[background.ID] = background background.client.close(code=9999, reason="") log.warn("Client connected while background " + str(id) + " was connected") if self.isBackground and not isConnectedABackground: self.close(code=9999, reason="") log.info("Connected background existing foreground: %s " % getUnicode(id)) return elif not self.isBackground and not isConnectedABackground: log.warn("Already connected user: %s " % getUnicode(id)) connections[id].client.close() del connections[id] return self.ID = self._commHandler.onOpen(id) clientType = "background" if self.isBackground else "client" log.info("open new %s with ID: %s " % (clientType, getUnicode(self.ID)))
def open(self, *args): try: id = int(args[0]) except: id = None self.ID = self._commHandler.onOpen(id) log.debug("open new connection with ID: %s " % getUnicode(self.ID))
def __executeFunction(self): try: return True, self.method(*self.args) except Exception as e: log.exception("Error calling hub function") return False, getUnicode(e)
def on_message(self, message): log.debug("Message received from ID: %s\n%s " % (getUnicode(self.ID), getUnicode(message))) self._commHandler.onAsyncMessage(message)