Status messages for client
This commit is contained in:
parent
0be692f4f2
commit
0d064555b4
@ -23,8 +23,10 @@ import socket
|
|||||||
import threading
|
import threading
|
||||||
import queue
|
import queue
|
||||||
|
|
||||||
|
def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)
|
||||||
|
|
||||||
bufferSize = 10000 # buffer size in bytes
|
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?
|
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
|
timeout = 15 # timeout in seconds
|
||||||
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
@ -49,13 +51,15 @@ class stdinThread(threading.Thread):
|
|||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
accumulatedData = self.queue.qsize() * bufferSize
|
accumulatedData = self.queue.qsize() * bufferSize
|
||||||
print("Accumulated MB: " +str(accumulatedData/1000000))
|
|
||||||
|
|
||||||
if queueLengthWait < 1 and accumulatedData > maxAccumulatedData:
|
if queueLengthWait < 1:
|
||||||
print("Accumulated data limit reached. Closing.")
|
eprint("Accumulated MB: " +str(accumulatedData/1000000))
|
||||||
self.connection.close()
|
|
||||||
self.queue = False
|
if accumulatedData > maxAccumulatedData:
|
||||||
return
|
eprint("Accumulated data limit reached. Closing.")
|
||||||
|
self.connection.close()
|
||||||
|
self.queue = False
|
||||||
|
return
|
||||||
data = self.queue.get()
|
data = self.queue.get()
|
||||||
self.connection.sendall(data)
|
self.connection.sendall(data)
|
||||||
except:
|
except:
|
||||||
@ -86,15 +90,15 @@ def main():
|
|||||||
serverAddr = sys.argv[1].rsplit(":",1)
|
serverAddr = sys.argv[1].rsplit(":",1)
|
||||||
serverAddr[1] = int(serverAddr[1])
|
serverAddr[1] = int(serverAddr[1])
|
||||||
serverAddr = tuple(serverAddr)
|
serverAddr = tuple(serverAddr)
|
||||||
print("Connecting to server...")
|
eprint("Connecting to server...")
|
||||||
connection.settimeout(timeout)
|
connection.settimeout(timeout)
|
||||||
connection.connect(serverAddr)
|
connection.connect(serverAddr)
|
||||||
print("Sending payload...")
|
eprint("Sending payload...")
|
||||||
connection.sendall(makePayload(sys.argv[2:]))
|
connection.sendall(makePayload(sys.argv[2:]))
|
||||||
print("Ready.")
|
|
||||||
|
|
||||||
if sys.argv[2] == "watch":
|
if sys.argv[2] == "watch":
|
||||||
try:
|
try:
|
||||||
|
eprint("Receiving data...")
|
||||||
stdoutThr = stdoutThread()
|
stdoutThr = stdoutThread()
|
||||||
stdoutThr.start()
|
stdoutThr.start()
|
||||||
while True:
|
while True:
|
||||||
@ -107,6 +111,7 @@ def main():
|
|||||||
|
|
||||||
if sys.argv[2] == "broadcast":
|
if sys.argv[2] == "broadcast":
|
||||||
try:
|
try:
|
||||||
|
eprint("Sending data...")
|
||||||
stdinThr = stdinThread(connection)
|
stdinThr = stdinThread(connection)
|
||||||
stdinThr.start()
|
stdinThr.start()
|
||||||
while True:
|
while True:
|
||||||
|
Loading…
Reference in New Issue
Block a user