File: async_multicast_receiver.py

package info (click to toggle)
python-txosc 0.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 304 kB
  • sloc: python: 1,857; makefile: 8
file content (35 lines) | stat: -rwxr-xr-x 1,066 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
"""
Example of a multicast UDP txosc receiver with Twisted.

You can run many of these on a single host.

This example is in the public domain.
"""
from twisted.internet import reactor
from txosc import osc
from txosc import dispatch
from txosc import async

class MulticastUDPReceiverApplication(object):
    """
    Example that receives multicast UDP OSC messages.
    """
    def __init__(self, port):
        self.port = port
        self.receiver = dispatch.Receiver()
        self._server_port = reactor.listenMulticast(self.port, async.MulticastDatagramServerProtocol(self.receiver, "224.0.0.1"), listenMultiple=True)
        print("Listening on osc.udp://224.0.0.1:%s" % (self.port))
        self.receiver.addCallback("/spam", self.spam_handler)
    
    def spam_handler(self, message, address):
        """
        Method handler for /spam
        """
        print("spam_handler")
        print("  Got %s from %s" % (message, address))

if __name__ == "__main__":
    app = MulticastUDPReceiverApplication(18888)
    reactor.run()