From 0d064555b4bac4d76439d3186dab64824ce3ee21 Mon Sep 17 00:00:00 2001 From: Fierelier Date: Wed, 21 Apr 2021 13:16:28 +0200 Subject: [PATCH] Status messages for client --- fstream-client.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/fstream-client.py b/fstream-client.py index cf10fa9..f32b16b 100644 --- a/fstream-client.py +++ b/fstream-client.py @@ -23,8 +23,10 @@ import socket import threading import queue +def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) + bufferSize = 10000 # buffer size in bytes -queueLengthWait = 10 # How many buffers can be in the queue before waiting? 0 for infinite, maxAccumulatedData comes into play. Raise for smoother playback, lower for less delay. +queueLengthWait = 10 # How many buffers can be in the queue before waiting for it to empty? 0 for infinite, maxAccumulatedData comes into play. Raise for smoother playback, lower for less delay. maxAccumulatedData = 50*1000*1000 # If queueLengthWait is 0, how much data can be in an outbound thread's queue at maximum before the connection is closed? timeout = 15 # timeout in seconds connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -49,13 +51,15 @@ class stdinThread(threading.Thread): try: while True: accumulatedData = self.queue.qsize() * bufferSize - print("Accumulated MB: " +str(accumulatedData/1000000)) - if queueLengthWait < 1 and accumulatedData > maxAccumulatedData: - print("Accumulated data limit reached. Closing.") - self.connection.close() - self.queue = False - return + if queueLengthWait < 1: + eprint("Accumulated MB: " +str(accumulatedData/1000000)) + + if accumulatedData > maxAccumulatedData: + eprint("Accumulated data limit reached. Closing.") + self.connection.close() + self.queue = False + return data = self.queue.get() self.connection.sendall(data) except: @@ -86,15 +90,15 @@ def main(): serverAddr = sys.argv[1].rsplit(":",1) serverAddr[1] = int(serverAddr[1]) serverAddr = tuple(serverAddr) - print("Connecting to server...") + eprint("Connecting to server...") connection.settimeout(timeout) connection.connect(serverAddr) - print("Sending payload...") + eprint("Sending payload...") connection.sendall(makePayload(sys.argv[2:])) - print("Ready.") if sys.argv[2] == "watch": try: + eprint("Receiving data...") stdoutThr = stdoutThread() stdoutThr.start() while True: @@ -107,6 +111,7 @@ def main(): if sys.argv[2] == "broadcast": try: + eprint("Sending data...") stdinThr = stdinThread(connection) stdinThr.start() while True: