Skip to content
Snippets Groups Projects
Commit d428771c authored by Quoc Nguyen Dao's avatar Quoc Nguyen Dao
Browse files

Fix server server discovery

parent 033e317f
No related branches found
No related tags found
1 merge request!2leader election und heartbeat
...@@ -3,7 +3,6 @@ import threading ...@@ -3,7 +3,6 @@ import threading
from datetime import datetime from datetime import datetime
import time import time
BROADCAST_IP = "192.168.0.255"
# Listening port Server Discovery # Listening port Server Discovery
SERVER_BROADCAST_PORT = 5974 SERVER_BROADCAST_PORT = 5974
...@@ -15,6 +14,8 @@ CLIENT_BROADCAST_PORT = 5973 ...@@ -15,6 +14,8 @@ CLIENT_BROADCAST_PORT = 5973
MY_HOST = socket.gethostname() MY_HOST = socket.gethostname()
MY_IP = socket.gethostbyname(MY_HOST) MY_IP = socket.gethostbyname(MY_HOST)
BROADCAST_IP = '.'.join(MY_IP.split('.')[:-1] + ['255'])
class Server(): class Server():
def __init__(self): def __init__(self):
self.leader_IP = '' # fix the leader IP self.leader_IP = '' # fix the leader IP
...@@ -99,6 +100,7 @@ class Server(): ...@@ -99,6 +100,7 @@ class Server():
num_responses = 0 num_responses = 0
while currentLoop < maxLoop: while currentLoop < maxLoop:
print("Waiting for responses...") # Debug-Ausgabe
while True: while True:
currentLoop += 1 currentLoop += 1
...@@ -109,12 +111,16 @@ class Server(): ...@@ -109,12 +111,16 @@ class Server():
if reply: if reply:
reply_address = reply.decode() reply_address = reply.decode()
# Debug-Ausgabe
print(f"Received response from: {reply_address}")
# if reply address is not in the server list, add it # if reply address is not in the server list, add it
if reply_address not in self.serverList: if reply_address not in self.serverList:
self.serverList.append(reply_address) self.serverList.append(reply_address)
# Erhöhe die Anzahl der eingehenden Antworten # Erhöhe die Anzahl der eingehenden Antworten
num_responses += 1 num_responses += 1
print(f"Current server list: {self.serverList}") # Debug-Ausgabe
except socket.timeout: except socket.timeout:
break break
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment