Example #1
0
 def __init__(self, conn):
     """ Initialize the protocol.
                             
         @param conn:        Connection instance which provides callback
                             functions.
         @type  conn:        pyrce.connection._Connection
     """
     self._connection = conn
     self._assembler = MessageAssembler(self, 60)
     self._registered = False
Example #2
0
class RCERobotProtocol(WebSocketClientProtocol):
    """ WebSocket client protocol which is used to communicate with the Robot
        Manager.
    """
    def __init__(self, conn):
        """ Initialize the protocol.
                                
            @param conn:        Connection instance which provides callback
                                functions.
            @type  conn:        pyrce.connection._Connection
        """
        self._connection = conn
        self._assembler = MessageAssembler(self, 60)
        self._registered = False
    
    def onOpen(self):
        """ This method is called by twisted as soon as the websocket
            connection has been successfully established.
        """
        self._assembler.start()
        self._connection.registerConnection(self)
        self._registered = True
    
    def onMessage(self, msg, binary):
        """ This method is called by twisted when a new message has been
            received.
        """
        self._assembler.processMessage(msg, binary)
    
    def processCompleteMessage(self, msg):
        """ Callback for MessageAssembler which will be called as soon as a
            message has been completed and is ready for processing.
        """
        self._connection.receivedMessage(msg)
    
    def onClose(self, *a):
        """ This method is called by twisted when the connection has been
            closed.
        """
        if self._registered:
            self._connection.unregisterConnection(self)
            self._assembler.stop()
            self._registered = False
    
    def failHandshake(self, reason):
        """ This method is called by twisted when the connection could not be
            initialized.
        """
        print(reason)
        WebSocketClientProtocol.failHandshake(self, reason)