From d926143913edc200c87d6724f34500a687814cd7 Mon Sep 17 00:00:00 2001 From: Fierelier Date: Tue, 20 Apr 2021 16:32:56 +0200 Subject: [PATCH] Add queueLengthWait, tweak bufferSize --- fstream-client.py | 9 +++++---- fstream-server.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/fstream-client.py b/fstream-client.py index 23d3a11..c822f3e 100644 --- a/fstream-client.py +++ b/fstream-client.py @@ -23,8 +23,9 @@ import socket import threading import queue -bufferSize = 50000 # buffer size in bytes -maxAccumulatedData = 50*1000*1000 # How much data can be in an outbound thread's queue at maximum before the connection is closed? +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. +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) @@ -41,7 +42,7 @@ class stdoutThread(threading.Thread): class stdinThread(threading.Thread): def __init__(self,connection): threading.Thread.__init__(self) - self.queue = queue.Queue() + self.queue = queue.Queue(queueLengthWait) self.connection = connection def run(self): @@ -50,7 +51,7 @@ class stdinThread(threading.Thread): accumulatedData = self.queue.qsize() * bufferSize print("Accumulated MB: " +str(accumulatedData/1000000)) - if accumulatedData > maxAccumulatedData: + if queueLengthWait < 1 and accumulatedData > maxAccumulatedData: print("Accumulated data limit reached. Closing.") self.connection.close() self.queue = False diff --git a/fstream-server.py b/fstream-server.py index 2be2784..60c7e0d 100644 --- a/fstream-server.py +++ b/fstream-server.py @@ -36,7 +36,7 @@ connectionsLock = threading.Lock() serverAddr = ("127.0.0.1",61920) serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -bufferSize = 50000 # Buffer size in bytes +bufferSize = 10000 # Buffer size in bytes timeout = 15 # How long to wait for a connection to respond before timing out? maxClients = 20 # How many clients can be connected at maximum? maxClientsPerIP = 3 # How many clients can be connected at maximum, per IP?