Commit 9d8eeec9 authored by Taddeus Kroes's avatar Taddeus Kroes

Made TUIO server more robust against stopping of the program.

parent 1aff9a2e
...@@ -15,7 +15,7 @@ class TuioServer2D(Logger): ...@@ -15,7 +15,7 @@ class TuioServer2D(Logger):
# OSC server that listens to incoming TUIO events # OSC server that listens to incoming TUIO events
self.server = OSCServer(self.__class__._tuio_address) self.server = OSCServer(self.__class__._tuio_address)
#self.server.addDefaultHandlers() self.server.addDefaultHandlers()
self.server.addMsgHandler('/tuio/2Dobj', self._receive) self.server.addMsgHandler('/tuio/2Dobj', self._receive)
self.server.addMsgHandler('/tuio/2Dcur', self._receive) self.server.addMsgHandler('/tuio/2Dcur', self._receive)
self.server.addMsgHandler('/tuio/2Dblb', self._receive) self.server.addMsgHandler('/tuio/2Dblb', self._receive)
...@@ -67,8 +67,11 @@ class TuioServer2D(Logger): ...@@ -67,8 +67,11 @@ class TuioServer2D(Logger):
self.handler_obj.point_down(sid, x, y) self.handler_obj.point_down(sid, x, y)
def start(self): def start(self):
try:
self.log('Starting OSC server') self.log('Starting OSC server')
self.server.serve_forever() self.server.serve_forever()
except SystemExit:
self.stop()
def stop(self): def stop(self):
self.log('Stopping OSC server') self.log('Stopping OSC server')
...@@ -90,4 +93,8 @@ if __name__ == '__main__': ...@@ -90,4 +93,8 @@ if __name__ == '__main__':
v = 1 if len(sys.argv) < 2 else int(sys.argv[1]) v = 1 if len(sys.argv) < 2 else int(sys.argv[1])
server = TuioServer2D(Handler(verbose=v), verbose=v) server = TuioServer2D(Handler(verbose=v), verbose=v)
try:
server.start() server.start()
except KeyboardInterrupt:
server.stop()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment