Tutorial

Table Of Contents
110
tcpSerSock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1)
tcpSerSock.bind(ADDR)
tcpSerSock.listen(5)
'''
Start listening to the client connection, after the client connection is successful, start to receive the information sent
from the client
'''
tcpCliSock, addr = tcpSerSock.accept()
while True:
data = ''
'''
Receive information from the client
'''
data = str(tcpCliSock.recv(BUFSIZ).decode())
if not data:
continue
'''
Turn on the light if the information content is on
If the information content is off, turn off the light
'''
elif 'on' == data:
for i in range(strip.numPixels()):
strip.setPixelColor(i, Color(255, 0, 255))
strip.show()
elif 'off' == data:
for i in range(strip.numPixels()):
strip.setPixelColor(i, Color(0, 0, 0))
strip.show()
'''
Finally print out the received data and start to continue listening to the next message from the client
'''
print(data)
The program of the client in the PC is as follows:
'''
Import socket library to be used for TCP communication
'''
from socket import *