From 1277312b41c4c4645f862e203ed88ac491d9ae2d Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 14 May 2014 04:02:00 +0200 Subject: m + add test client MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- test.d/dumb-client | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 test.d/dumb-client (limited to 'test.d/dumb-client') diff --git a/test.d/dumb-client b/test.d/dumb-client new file mode 100755 index 0000000..4868813 --- /dev/null +++ b/test.d/dumb-client @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# -*- python -*- + +# mds — A micro-display server +# Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import os +import sys +import socket +import threading + + +display = os.environ['MDS_DISPLAY'] if 'MDS_DISPLAY' in os.environ else None +if (display is None) or (':' not in display): + print('MDS_DISPLAY has not set.') + sys.exit(1) +if not display.startswith(':'): + print('Remote mds sessions are not supported.') + sys.exit(1) + +socket_path = '/run/mds/%s.socket' % display.split(':')[-1] +socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) +socket.connect(socket_path) + +def read_loop(): + data = socket.recv(1); + if not data: + return + sys.stdout.buffer.write(b'\033[34m'); + sys.stdout.buffer.write(data); + sys.stdout.buffer.write(b'\033[00m'); + sys.stdout.buffer.flush(); + +thread = threading.Thread(target = read_loop) +thread.setDaemon(True) +thread.start() + +while True: + try: + data = input().encode('utf-8') + except: + break + socket.send(data); + +socket.close() + -- cgit v1.2.3-70-g09d2