Created
December 7, 2012 21:56
-
-
Save keiya/4236844 to your computer and use it in GitHub Desktop.
python udp to websocket bridge for KinectServer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import threading, socket, queue , pprint, msgpack | |
| q = queue.Queue(64) | |
| pp = pprint.PrettyPrinter(indent=4) | |
| class Receiver(threading.Thread): | |
| def __init__(self): | |
| self.result = None | |
| threading.Thread.__init__(self) | |
| def run(self): | |
| self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
| self.sock.bind((socket.gethostname(),65487)) | |
| while True: | |
| res = self.sock.recv(2048) | |
| humans = msgpack.unpackb(res) | |
| q.put(humans, True) | |
| def main(): | |
| def producer(): | |
| thread = Receiver() | |
| thread.start() | |
| def consumer(): | |
| while True: | |
| humans = q.get(True) | |
| pp.pprint(humans) | |
| prod_thread = threading.Thread(target=producer) | |
| cons_thread = threading.Thread(target=consumer) | |
| prod_thread.start() | |
| cons_thread.start() | |
| prod_thread.join() | |
| cons_thread.join() | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment