/usr/bin/osc-receive is in python-txosc 0.2.0-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | #!/usr/bin/python
# Copyright (c) 2009 Alexandre Quessy, Arjan Scherpenisse
# See LICENSE for details.
"""
OSC receiver made with txosc
"""
import sys
import optparse
from twisted.internet import reactor
import txosc # for __version__
from txosc import osc
from txosc import dispatch
from txosc import async
VERBOSE = False
def verb(txt):
"""
Prints a message if in verbose mode.
"""
global VERBOSE
if VERBOSE:
print(txt)
def fallback(message, address):
"""
Fallback for any unhandled message
"""
print("%s from %s" % (message, address))
def _exit(txt):
print(txt)
sys.exit(1)
class OscDumper(object):
"""
Prints OSC messages it receives.
"""
def __init__(self, protocol, port, multicast_group=None):
self.receiver = dispatch.Receiver()
if protocol == "UDP":
if multicast_group is not None:
self._server_port = reactor.listenMulticast(port, async.MulticastDatagramServerProtocol(self.receiver, multicast_group), listenMultiple=True)
else:
self._server_port = reactor.listenUDP(port, async.DatagramServerProtocol(self.receiver))
else:
self._server_port = reactor.listenTCP(port, async.ServerFactory(self.receiver))
host = "localhost"
if multicast_group is not None:
host = multicast_group
print("Listening on osc.%s://%s:%s" % (protocol.lower(), host, port))
# fallback:
self.receiver.setFallback(fallback)
if __name__ == "__main__":
parser = optparse.OptionParser(usage="%prog", version=txosc.__version__.strip(), description=__doc__)
parser.add_option("-p", "--port", type="int", default=31337, help="Port to listen on")
parser.add_option("-g", "--multicast-group", type="string", help="Multicast group to listen on")
parser.add_option("-v", "--verbose", action="store_true", help="Makes the output verbose")
parser.add_option("-T", "--tcp", action="store_true", help="Uses TCP instead of UDP")
(options, args) = parser.parse_args()
app = None
protocol = "UDP"
multicast_group = None
if options.tcp:
protocol = "TCP"
if options.multicast_group:
if protocol != "UDP":
_exit("Multicast groups are only supported with UDP.")
else:
multicast_group = options.multicast_group
def _later():
app = OscDumper(protocol, options.port, multicast_group)
reactor.callLater(0.01, _later)
reactor.run()
|