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
7f267d83
Commit
7f267d83
authored
6 months ago
by
Katharina
Browse files
Options
Downloads
Patches
Plain Diff
add left the chat (msg not send...)
parent
b7cd16d6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
2024-12-22_Server_V4.py
+1
-1
1 addition, 1 deletion
2024-12-22_Server_V4.py
2025-01-01_Client_V4.py
+24
-8
24 additions, 8 deletions
2025-01-01_Client_V4.py
with
25 additions
and
9 deletions
2024-12-22_Server_V4.py
+
1
−
1
View file @
7f267d83
...
@@ -348,7 +348,7 @@ def listen_client():
...
@@ -348,7 +348,7 @@ def listen_client():
hold_back_queue
.
append
((
message_id
,
decoded_message
))
# Add the message to the hold-back queue
hold_back_queue
.
append
((
message_id
,
decoded_message
))
# Add the message to the hold-back queue
process_hold_back_queue
()
# Process messages in the hold-back queue
process_hold_back_queue
()
# Process messages in the hold-back queue
except
socket
.
error
as
e
:
# Handle socket errors
except
socket
.
error
as
e
:
# Handle socket errors
print
(
f
"
An error occurred:
{
e
}
"
)
print
(
f
"
An error occurred
while listening
:
{
e
}
"
)
break
break
except
KeyboardInterrupt
:
# Handle server shutdown via keyboard interrupt ????? Funktioniert das??
except
KeyboardInterrupt
:
# Handle server shutdown via keyboard interrupt ????? Funktioniert das??
print
(
"
\n
Shutting down server...
"
)
print
(
"
\n
Shutting down server...
"
)
...
...
This diff is collapsed.
Click to expand it.
2025-01-01_Client_V4.py
+
24
−
8
View file @
7f267d83
...
@@ -2,6 +2,7 @@ import socket
...
@@ -2,6 +2,7 @@ import socket
import
threading
import
threading
import
time
import
time
import
uuid
import
uuid
import
sys
broadcast_ip
=
'
255.255.255.255
'
#change ip??? #hard coded?
broadcast_ip
=
'
255.255.255.255
'
#change ip??? #hard coded?
broadcast_port
=
55555
broadcast_port
=
55555
...
@@ -57,8 +58,8 @@ def listen_server():
...
@@ -57,8 +58,8 @@ def listen_server():
#print("this decoded msg", decoded_message) #debug
#print("this decoded msg", decoded_message) #debug
except
socket
.
error
as
e
:
except
socket
.
error
as
e
:
print
(
f
"
An error occurred:
{
e
}
"
)
print
(
f
"
An error occurred
while listening
:
{
e
}
"
)
break
continue
def
sender
():
def
sender
():
...
@@ -70,18 +71,33 @@ def sender():
...
@@ -70,18 +71,33 @@ def sender():
#client_socket.sendto(just_nickname, (broadcast_ip, broadcast_port))
#client_socket.sendto(just_nickname, (broadcast_ip, broadcast_port))
client_socket
.
sendto
(
just_nickname
,
(
broadcast_ip
,
broadcast_port
))
client_socket
.
sendto
(
just_nickname
,
(
broadcast_ip
,
broadcast_port
))
#print("is it leader adresse here", leader_address)
#print("is it leader adresse here", leader_address)
while
True
:
try
:
while
True
:
#allows the client to send any message
#allows the client to send any message
message
=
input
(
""
)
message
=
input
(
""
)
#print("send message to", broadcast_port)
#print("send message to", broadcast_port)
#checks for whitemarks
#checks for whitemarks
if
message
.
strip
():
if
message
.
strip
():
message_id
=
str
(
uuid
.
uuid4
())
message_id
=
str
(
uuid
.
uuid4
())
full_message
=
f
"
{
message_id
}
:
{
nickname
}
:
{
message
}
"
.
encode
()
full_message
=
f
"
{
message_id
}
:
{
nickname
}
:
{
message
}
"
.
encode
()
client_socket
.
sendto
(
full_message
,
(
broadcast_ip
,
broadcast_port
))
client_socket
.
sendto
(
full_message
,
(
broadcast_ip
,
broadcast_port
))
#print("message sended to", broadcast_port)
#print("message sended to", broadcast_port)
except
KeyboardInterrupt
:
# Handle when the user presses Ctrl+C
print
(
f
"
\n
{
nickname
}
left the chat.
"
)
# Notify others that this client left the chat
message_id
=
str
(
uuid
.
uuid4
())
# New message ID
leave_message
=
f
"
{
nickname
}
left the chat
"
.
encode
()
client_socket
.
sendto
(
leave_message
,
(
broadcast_ip
,
broadcast_port
))
time
.
sleep
(
2
)
# Gracefully close the socket
client_socket
.
close
()
sys
.
exit
()
# Exit the program
###############main#################################
###############main#################################
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
# Start listener thread
# Start listener thread
...
...
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