示例#1
0
def handle_osc(data, src, dispatch=None, strict=False):
    try:
        head, _ = split_oscstr(data, 0)

        if head.startswith("/"):
            messages = [(-1, parse_message(data, strict))]
        elif head == "#bundle":
            messages = parse_bundle(data, strict)
    except Exception as exc:
        if __debug__:
            log.debug("Could not parse message from %s:%i: %s",
                      *get_hostport(src), exc)
            log.debug("Data: %r", data)
        return

    try:
        for timetag, (oscaddr, tags, args) in messages:
            if __debug__:
                log.debug("OSC address: %s" % oscaddr)
                log.debug("OSC type tags: %r" % tags)
                log.debug("OSC arguments: %r" % (args, ))

            if dispatch:
                dispatch(timetag, (oscaddr, tags, args, src))
    except Exception as exc:
        log.error("Exception in OSC handler: %s", exc)
示例#2
0
 def __call__(self, t, msg):
     self.count += 1
     print("OSC message from: udp://%s:%s" % get_hostport(msg[3]))
     print("OSC address:", msg[0])
     print("Type tags:", msg[1])
     print("Arguments:", msg[2])
     print()
示例#3
0
def handle_osc(data, src, dispatch=None, strict=False):
    try:
        head, _ = split_oscstr(data, 0)

        if head.startswith('/'):
            messages = [(-1, parse_message(data, strict))]
        elif head == '#bundle':
            messages = parse_bundle(data, strict)
    except:
        if __debug__:
            log.debug("Could not parse message from %s:%i.",
                      *get_hostport(src))
            log.debug("Data: %r", data)
        return

    try:
        for timetag, (oscaddr, tags, args) in messages:
            if __debug__:
                log.debug("OSC address: %s" % oscaddr)
                log.debug("OSC type tags: %r" % tags)
                log.debug("OSC arguments: %r" % (args,))

            if dispatch:
                dispatch(timetag, (oscaddr, tags, args, src))
    except Exception as exc:
        log.error("Exception in OSC handler: %s", exc)
 def __call__(self, t, msg):
     self.count += 1
     print("OSC message from: udp://%s:%s" % get_hostport(msg[3]))
     print("OSC address:", msg[0])
     print("Type tags:", msg[1])
     print("Arguments:", msg[2])
     print()
示例#5
0
def run_server(saddr, port, handler=handle_osc):
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    if __debug__: log.debug("Created OSC UDP server socket.")

    sock.bind((saddr, port))
    log.info("Listening for OSC messages on %s:%i.", saddr, port)

    try:
        while True:
            data, caddr = sock.recvfrom(MAX_DGRAM_SIZE)
            if __debug__: log.debug("RECV %i bytes from %s:%s",
                                    len(data), *get_hostport(caddr))
            handler(data, caddr)
    finally:
        sock.close()
        log.info("Bye!")
示例#6
0
def run_server(saddr, port, handler=handle_osc):
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    if __debug__:
        log.debug("Created OSC UDP server socket.")

    sock.bind((saddr, port))
    log.info("Listening for OSC messages on %s:%i.", saddr, port)

    try:
        while True:
            data, caddr = sock.recvfrom(MAX_DGRAM_SIZE)
            if __debug__:
                log.debug("RECV %i bytes from %s:%s", len(data), *get_hostport(caddr))
            handler(data, caddr)
    finally:
        sock.close()
        log.info("Bye!")
示例#7
0
def run_server(host, port, client_coro, **params):
    if __debug__: log.debug("run_server(%s, %s)", host, port)
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.setblocking(False)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.bind((host, port))

    try:
        while True:
            if __debug__: log.debug("run_server: Before IORead")
            yield IORead(sock)
            if __debug__: log.debug("run_server: Before recvfrom")
            data, caddr = sock.recvfrom(MAX_DGRAM_SIZE)
            if __debug__: log.debug("RECV %i bytes from %s:%s",
                                    len(data), *get_hostport(caddr))
            yield client_coro(data, caddr, **params)
    finally:
        sock.close()
        log.info("Bye!")
def run_server(host, port, client_coro, **params):
    if __debug__: log.debug("run_server(%s, %s)", host, port)
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.setblocking(False)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.bind((host, port))

    try:
        while True:
            if __debug__: log.debug("run_server: Before IORead")
            yield IORead(sock)
            if __debug__: log.debug("run_server: Before recvfrom")
            data, caddr = sock.recvfrom(MAX_DGRAM_SIZE)
            if __debug__:
                log.debug("RECV %i bytes from %s:%s", len(data),
                          *get_hostport(caddr))
            yield client_coro(data, caddr, **params)
    finally:
        sock.close()
        log.info("Bye!")