add client interface

This commit is contained in:
Lucca Ketterer 2020-06-06 23:35:53 +02:00
parent 1ed6209465
commit c6e80956e5

View File

@ -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 <color> 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:])