Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup server thread #11

Merged
merged 2 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)