Skip to content

Commit

Permalink
Fix search for available scale_id
Browse files Browse the repository at this point in the history
Broke when already connected to 6 scales
or when scale_id didn't get reset
  • Loading branch information
krameler committed Jan 8, 2020
1 parent 730e750 commit bc0cf7a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def clientThread(client_id, conn, client_ip, port):


def startServer():
scale_id = 0
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# this is for easy starting/killing the app
soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Expand All @@ -66,16 +65,19 @@ def startServer():
while True:
conn, addr = soc.accept()
ip, port = str(addr[0]), str(addr[1])
while True: # checking for available scale ids
if variables.list_scale_id[scale_id] == False:
break
scale_id += 1

#checking for available scale ids
try:
scale_id = variables.list_scale_id.index(False)
except ValueError:
print('Connection refused: No available scale_id found!')
conn.close()
continue
print('Accepting connection from ' + ip + ':' + port + ' Id is:' + str(scale_id))
try:

Thread(target=clientThread, args=(scale_id, conn, ip, port), daemon=True).start()
variables.list_scale_id[scale_id] = True
scale_id = 0
except:
print("Terrible error!")
import traceback
Expand Down

0 comments on commit bc0cf7a

Please sign in to comment.