Added broken pipe handling.
This commit is contained in:
parent
3a7894e052
commit
df59ddfc34
12
slave.py
12
slave.py
@ -1,7 +1,8 @@
|
||||
import socket
|
||||
import sys
|
||||
|
||||
ledNames = [
|
||||
|
||||
ledNames = [
|
||||
"power",
|
||||
"lan0",
|
||||
"lan1",
|
||||
@ -37,7 +38,8 @@ def setLed(index, color):
|
||||
finally:
|
||||
file.close()
|
||||
|
||||
def handleData(data):
|
||||
|
||||
def handleData(data):
|
||||
databyline = data.split("\n")
|
||||
try:
|
||||
for i in range(len(databyline)):
|
||||
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user