Skip to content
Snippets Groups Projects
Commit be4acda2 authored by Katharina's avatar Katharina
Browse files

delete and add comments

parent 38448f8d
No related merge requests found
...@@ -19,7 +19,7 @@ last_heartbeat = time.time() ...@@ -19,7 +19,7 @@ last_heartbeat = time.time()
processed_message_ids = set() # A set to track the IDs of messages that have already been processed. This helps avoid duplicate processing. processed_message_ids = set() # A set to track the IDs of messages that have already been processed. This helps avoid duplicate processing.
listener_ready = threading.Event() listener_ready = threading.Event()
########################### Start - Receiving MSG ########################### ########################### Start - Receiving messages ###########################
def listen_server(): def listen_server():
""" """
Listens for messages broadcasted by the server and processes them. Listens for messages broadcasted by the server and processes them.
...@@ -38,10 +38,7 @@ def listen_server(): ...@@ -38,10 +38,7 @@ def listen_server():
received_uuid, rest_of_text = text.split(":", 1) # Split the message into UUID (unique identifier) and the rest of the text received_uuid, rest_of_text = text.split(":", 1) # Split the message into UUID (unique identifier) and the rest of the text
if received_uuid not in processed_message_ids: # Process the message if it hasn't been processed yet if received_uuid not in processed_message_ids: # Process the message if it hasn't been processed yet
processed_message_ids.add(received_uuid) # Mark the message as processed processed_message_ids.add(received_uuid) # Mark the message as processed
#print(f"Received {data.decode()} from {address}") # Only for Debugging print(rest_of_text) # Display the message content
print(rest_of_text) # Display the message content
#else: ################### Only for debugging
# print("Message ist Doppelt") ################### Only for debugging
except socket.error as e: # Handle and log any errors while listening for messages except socket.error as e: # Handle and log any errors while listening for messages
print(f"An error occurred while listening: {e}") print(f"An error occurred while listening: {e}")
continue continue
...@@ -61,7 +58,7 @@ def sender(): ...@@ -61,7 +58,7 @@ def sender():
client_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) client_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
client_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) client_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
client_socket.sendto(just_nickname, (broadcast_ip, broadcast_port)) #Send the "entered the chat" message to the broadcast address client_socket.sendto(just_nickname, (broadcast_ip, broadcast_port)) #Send the "entered the chat" message to the broadcast address
processed_message_ids.add(message_id) # Mark the message ID as processed #######+ Können wir als Rückmeldung auch ausgeben lassen processed_message_ids.add(message_id) # Mark the message ID as processed
try: try:
while True: while True:
message = input("") # Allow the user to enter a message message = input("") # Allow the user to enter a message
...@@ -96,7 +93,6 @@ def listen_to_heartbeat(): ...@@ -96,7 +93,6 @@ def listen_to_heartbeat():
while True: while True:
try: # Wait for incoming heartbeat messages try: # Wait for incoming heartbeat messages
data, addr = client_heartbeat_socket.recvfrom(1024) # Receive data from the socket data, addr = client_heartbeat_socket.recvfrom(1024) # Receive data from the socket
#print("Server heartbeat received.") # Log that the server's heartbeat was received - Only for De bugging
last_heartbeat = time.time() # Update the timestamp for the last received heartbeat last_heartbeat = time.time() # Update the timestamp for the last received heartbeat
except Exception as e: # Handle and log any errors during data reception except Exception as e: # Handle and log any errors during data reception
print(f"Error sending data: {e}") print(f"Error sending data: {e}")
......
This diff is collapsed.
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