Exemplo n.º 1
0
class Connection(object):
    """
    A remote native-protocol connection.
    """
    def __init__(self, server, socket):
        self.server = server
        self.socket = socket
        self.queue = Queue()
        self.input_thread = InputThread(socket, self.message_received)
        self.output_thread = OutputThread(socket, self.queue.get)
    
    def start(self):
        self.input_thread.start()
        self.output_thread.start()
    
    def message_received(self, message):
        if message is None:
            self.server.post_event({"event": "disconnected",
                    "connection": self})
        self.server.remote_message_received(self, message)
    
    def send(self, message):
        self.queue.put(message)
Exemplo n.º 2
0
 def __init__(self, server, socket):
     self.server = server
     self.socket = socket
     self.queue = Queue()
     self.input_thread = InputThread(socket, self.message_received)
     self.output_thread = OutputThread(socket, self.queue.get)