Added broken pipe handling.

This commit is contained in:
Greenscreener 2019-09-24 21:13:49 +02:00
parent 3a7894e052
commit df59ddfc34

View File

@ -1,6 +1,7 @@
import socket
import sys
ledNames = [
"power",
"lan0",
@ -37,6 +38,7 @@ def setLed(index, color):
finally:
file.close()
def handleData(data):
databyline = data.split("\n")
try:
@ -84,13 +86,15 @@ while True:
allData+=data.decode('utf-8')
if allData.find('\n\n') > -1:
break
eprint('all data: {}'.format(allData))\
eprint('all data: {}'.format(allData))
if not handleData(allData) is 0:
conn.sendall("error".encode('utf-8'))
else:
conn.sendall("OK".encode('utf-8'))
except BrokenPipeError:
eprint("connection from {} has broken a pipe.".format(client_address))
conn.close()
finally:
# Clean up the connection
conn.close()