led_control/server/server.py

24 lines
635 B
Python

import socket
import ws2801
def start():
host = "0.0.0.0"
port = 5000
server_socket = socket.socket()
server_socket.bind((host, port))
# configure how many client the server can listen simultaneously
server_socket.listen(1)
conn, address = server_socket.accept() # accept new connection
print("Connection from: " + str(address))
while True:
# receive data stream. it won't accept data packet greater than 1024 bytes
data = conn.recv(1024).decode()
r,g,b = ws2801.hex_to_rgb(data)
ws2801.set_color(r,g,b)
conn.close() # close the connection
start()