Skip to content

Commit

Permalink
Merge pull request #11 from krameler/fixupServerThread
Browse files Browse the repository at this point in the history
Fixup server thread
  • Loading branch information
knoterich authored Jan 8, 2020
2 parents 730e750 + ad01dd1 commit 74b0dde
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 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
14 changes: 7 additions & 7 deletions variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
en_log = False
en_blink = False

list_scale_id = [False, False, False, False, False]
list_client_ip = ["NC", "NC", "NC", "NC", "NC"]
list_scale_id = [False, False, False, False, False, False]
list_client_ip = ["NC", "NC", "NC", "NC", "NC", "NC"]
list_cell_units = ["", "", "", "", "", ""]
list_scale_mom = ["", "", "", "", "", ""]
port_server = 4242

queues_recv = []
for i in range(5):
for i in range(6):
queues_recv.append(queue.Queue())

queues_send = []
for i in range(5):
for i in range(6):
queues_send.append(queue.Queue())

queues_ack = []
for i in range(5):
for i in range(6):
queues_ack.append(queue.Queue())

queues_mes = []
for i in range(5):
for i in range(6):
queues_mes.append(queue.LifoQueue())

lock_file_mes = []
for i in range(5):
for i in range(6):
lock = Lock()
lock_file_mes.append(lock)

0 comments on commit 74b0dde

Please sign in to comment.