client server communication implemented
This commit is contained in:
parent
28393b1dd4
commit
282c3f3a39
@ -3,15 +3,17 @@ import getopt
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
def connect(host, port = 5000):
|
||||
client_socket = socket.socket()
|
||||
server_IP = "192.168.188.61"
|
||||
|
||||
# instantiate
|
||||
client_socket.connect((host, port)) # connect to the server
|
||||
def connect(host, port = 5000):
|
||||
client_socket.connect((host, port))
|
||||
|
||||
def disconnect():
|
||||
client_socket.close() # close the connection
|
||||
|
||||
def send(data):
|
||||
#validate data. should be hex color
|
||||
client_socket.send(data.encode()) # send message
|
||||
|
||||
def helpmenu():
|
||||
@ -25,7 +27,6 @@ def visualizer():
|
||||
print(cava.stdout.readlines())
|
||||
|
||||
|
||||
|
||||
def main(argv):
|
||||
try:
|
||||
opts, args = getopt.getopt(argv, "s:vh")
|
||||
@ -39,12 +40,12 @@ def main(argv):
|
||||
helpmenu()
|
||||
sys.exit()
|
||||
elif opt == "-s":
|
||||
connect(server_IP)
|
||||
send(arg)
|
||||
elif opt == "-v":
|
||||
connect(server_IP)
|
||||
visualizer()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
client_socket = socket.socket()
|
||||
connect("192.168.188.61")
|
||||
main(sys.argv[1:])
|
||||
@ -1,7 +1,8 @@
|
||||
import socket
|
||||
import ws2801
|
||||
|
||||
def start_server():
|
||||
host = socket.gethostname()
|
||||
def start():
|
||||
host = "0.0.0.0"
|
||||
port = 5000
|
||||
|
||||
server_socket = socket.socket()
|
||||
@ -14,8 +15,9 @@ def start_server():
|
||||
while True:
|
||||
# receive data stream. it won't accept data packet greater than 1024 bytes
|
||||
data = conn.recv(1024).decode()
|
||||
print(str(data))
|
||||
r,g,b = ws2801.hex_to_rgb(data)
|
||||
ws2801.set_color(r,g,b)
|
||||
|
||||
|
||||
conn.close() # close the connection
|
||||
|
||||
start()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user