Exemplo n.º 1
0
    def dataReceived(self, data):
        """
        Called whenever data is received.

        In a stream-based protocol such as TCP, the stream should
        begin with an int32 giving the size of the first packet,
        followed by the contents of the first packet, followed by the
        size of the second packet, etc.

        @type data: L{str}
        """
        self._buffer += data
        if len(self._buffer) < 4:
            return
        if self._pkgLen is None:
            self._pkgLen = struct.unpack(">i", self._buffer[:4])[0]
        if len(self._buffer) < self._pkgLen + 4:
            print "waiting for %d more bytes" % (self._pkgLen + 4 -
                                                 len(self._buffer))
            return
        payload = self._buffer[4:4 + self._pkgLen]
        self._buffer = self._buffer[4 + self._pkgLen:]
        self._pkgLen = None

        if payload:
            element = _elementFromBinary(payload)
            self.factory.gotElement(element)

        if len(self._buffer):
            self.dataReceived("")
Exemplo n.º 2
0
Arquivo: async.py Projeto: aalex/txosc
    def dataReceived(self, data):
        """
        Called whenever data is received.

        In a stream-based protocol such as TCP, the stream should
        begin with an int32 giving the size of the first packet,
        followed by the contents of the first packet, followed by the
        size of the second packet, etc.

        @type data: L{str}
        """
        self._buffer += data
        if len(self._buffer) < 4:
            return
        if self._pkgLen is None:
            self._pkgLen = struct.unpack(">i", self._buffer[:4])[0]
        if len(self._buffer) < self._pkgLen + 4:
            print "waiting for %d more bytes" % (self._pkgLen + 4 - len(self._buffer))
            return
        payload = self._buffer[4:4 + self._pkgLen]
        self._buffer = self._buffer[4 + self._pkgLen:]
        self._pkgLen = None

        if payload:
            element = _elementFromBinary(payload)
            self.factory.gotElement(element)

        if len(self._buffer):
            self.dataReceived("")
Exemplo n.º 3
0
def _patched_elementFromBinary(data):
  if data[0] == "/":
    element, data = osc.Message.fromBinary(data)
  elif data[0] == "#":
    element, data = osc.Bundle.fromBinary(data)
  else:
    fixedData = _try_fixing_invalid_osc_data(data)
    if fixedData:
      element = osc._elementFromBinary(fixedData)
    else:
      raise osc.OscError("Error parsing OSC data: " + data)
  return element
Exemplo n.º 4
0
class DatagramServerProtocol(protocol.DatagramProtocol):
    """
    The UDP OSC server protocol.

    @ivar receiver: The L{Receiver} instance to dispatch received
        elements to.
    """
    def __init__(self, receiver):
        """
        @param receiver: L{Receiver} instance.
        """
        self.receiver = receiver

    def datagramReceived(self, data, (host, port)):
        element = _elementFromBinary(data)
        self.receiver.dispatch(element, (host, port))