Status messages for client
This commit is contained in:
parent
0be692f4f2
commit
0d064555b4
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user