From 809c06fa34e8fdad21acdeeb7aeee8ca994b7f40 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Wed, 30 Jul 2014 21:14:21 +0200 Subject: basic impl of remote-control server --- voctocore/controlserver.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'voctocore') 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 -- cgit v1.2.3