Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Distributed-Systems
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Katharina Willig
Distributed-Systems
Commits
be4acda2
Commit
be4acda2
authored
5 months ago
by
Katharina
Browse files
Options
Downloads
Patches
Plain Diff
delete and add comments
parent
38448f8d
Loading
Loading
No related merge requests found
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Client_25-01-25.py
+3
-7
3 additions, 7 deletions
Client_25-01-25.py
Server_25-01-25.py
+56
-58
56 additions, 58 deletions
Server_25-01-25.py
with
59 additions
and
65 deletions
Client_25-01-25.py
+
3
−
7
View file @
be4acda2
...
@@ -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.
Click to expand it.
Server_25-01-25.py
+
56
−
58
View file @
be4acda2
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment