From c6e80956e5d0ac6848995f68d30f485a34320cde Mon Sep 17 00:00:00 2001 From: Lucca Ketterer Date: Sat, 6 Jun 2020 23:35:53 +0200 Subject: [PATCH] add client interface --- client/client.py | 55 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/client/client.py b/client/client.py index 22e04dd..6446838 100644 --- a/client/client.py +++ b/client/client.py @@ -1,21 +1,50 @@ import socket +import getopt +import sys +import subprocess +def connect(host, port = 5000): -def client_program(): - host = "192.168.188.61" - port = 5000 - - client_socket = socket.socket() # instantiate + # instantiate client_socket.connect((host, port)) # connect to the server - message = input(" -> ") # take input - - while message.lower().strip() != 'bye': - client_socket.send(message.encode()) # send message - message = input(" -> ") # again take input - +def disconnect(): client_socket.close() # close the connection +def send(data): + client_socket.send(data.encode()) # send message -if __name__ == '__main__': - client_program() +def helpmenu(): + print("Options:") + print("-h show help") + print("-s set static color in hex") + print("-v visualizer()") + +def visualizer(): + with subprocess.Popen(["cava", "-p", "./config"], stdout=subprocess.PIPE) as cava: + print(cava.stdout.readlines()) + + + +def main(argv): + try: + opts, args = getopt.getopt(argv, "s:vh") + except getopt.GetoptError: + print(sys.argv[0], "invalid option") + print("Try", sys.argv[0], "-h for help") + sys.exit(1) + + for opt, arg in opts: + if opt == "-h": + helpmenu() + sys.exit() + elif opt == "-s": + send(arg) + elif opt == "-v": + visualizer() + + +if __name__ == "__main__": + client_socket = socket.socket() + connect("192.168.188.61") + main(sys.argv[1:]) \ No newline at end of file