diff options
author | MaZderMind <github@mazdermind.de> | 2014-07-30 21:14:21 +0200 |
---|---|---|
committer | MaZderMind <github@mazdermind.de> | 2014-07-30 21:14:21 +0200 |
commit | 809c06fa34e8fdad21acdeeb7aeee8ca994b7f40 (patch) | |
tree | fd7e663f2660b0eea5a130f95a30ddf8e7275ea3 | |
parent | 307e6fd40a687bdc72c46d7e1732ea24462a4755 (diff) |
basic impl of remote-control server
-rw-r--r-- | voctocore/controlserver.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/voctocore/controlserver.py b/voctocore/controlserver.py index 8397705..da27408 100644 --- a/voctocore/controlserver.py +++ b/voctocore/controlserver.py @@ -1,4 +1,33 @@ -class ControlServer: +import socket, threading, queue +from gi.repository import GObject +class ControlServer(): def __init__(self, videomix): + '''Initialize server and start listening.''' self.videomix = videomix + + sock = socket.socket() + sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + sock.bind(('0.0.0.0', 23000)) + sock.listen(1) + GObject.io_add_watch(sock, GObject.IO_IN, self.listener) + + def listener(self, sock, *args): + '''Asynchronous connection listener. Starts a handler for each connection.''' + conn, addr = sock.accept() + print("Connected") + GObject.io_add_watch(conn, GObject.IO_IN, self.handler) + return True + + def handler(self, conn, *args): + '''Asynchronous connection handler. Processes each line from the socket.''' + line = conn.recv(4096) + if not len(line): + print("Connection closed.") + return False + + livevideo = self.videomix.pipeline.get_by_name('livevideo') + pad = livevideo.get_static_pad('sink_1') + pad.set_property('alpha', 00) + print(line) + return True |