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
7e98b804
Commit
7e98b804
authored
7 months ago
by
Katharina
Browse files
Options
Downloads
Patches
Plain Diff
f
parent
d5e72d01
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
kclient.py
+10
-3
10 additions, 3 deletions
kclient.py
server.py
+4
-4
4 additions, 4 deletions
server.py
with
14 additions
and
7 deletions
kclient.py
+
10
−
3
View file @
7e98b804
...
...
@@ -14,6 +14,8 @@ MY_IP = socket.gethostbyname(MY_HOST)
print
(
f
"
Listening for leader response on
{
broadcast_ip
}
:
{
broadcast_port
}
...
"
)
print
(
MY_HOST
,
MY_IP
)
#stop_listening = False # control for listener
# create client-socket for broadcast
client_socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
client_socket
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_BROADCAST
,
1
)
...
...
@@ -36,8 +38,8 @@ def listen():
# continue
#ignores broadcast messages with own ip #################please enable it after testing!!!!!!!!!!!!!!!!!!!S
if
address
[
0
]
==
MY_IP
:
continue
#
if address[0]==MY_IP:
#
continue
#####identifyLEADER############
# Erkennen von LEADER-Nachrichten
...
...
@@ -45,8 +47,11 @@ def listen():
leader_uuid
=
decoded_message
.
split
(
"
:
"
)[
1
]
print
(
f
"
Leader discovered:
{
leader_uuid
}
at
{
address
[
0
]
}
:
{
address
[
1
]
}
"
)
leader_address
=
(
address
[
0
],
broadcast_port
)
# IP-Adresse des Leaders speichern
#print(leader_address)
continue
#################################
if
"
HEARTBEAT:
"
in
decoded_message
:
continue
print
(
decoded_message
)
...
...
@@ -64,6 +69,8 @@ def request_leader():
timeout
=
time
.
time
()
+
5
# 10 Sekunden auf Antwort warten
while
time
.
time
()
<
timeout
:
if
leader_address
:
#print("leader address:", leader_address)
#client_socket.sendto("REQUEST_LEAD finish".encode(), leader_address)
return
time
.
sleep
(
0.5
)
# Warten, bis eine Antwort vom Leader eintrifft
#print("No leader found. Unable to send messages.")
...
...
@@ -84,7 +91,7 @@ def sender():
just_nickname
=
f
"
{
nickname
}
entered the chat
"
.
encode
()
#client_socket.sendto(just_nickname, (broadcast_ip, broadcast_port))
client_socket
.
sendto
(
just_nickname
,
leader_address
)
#print("is it leader adresse here", leader_address)
while
True
:
#allows the client to send any message
message
=
input
(
""
)
...
...
This diff is collapsed.
Click to expand it.
server.py
+
4
−
4
View file @
7e98b804
...
...
@@ -49,7 +49,7 @@ def listen(queue, shared_data):
if
"
REQUEST_LEAD
"
in
decoded_message
:
if
shared_data
[
'
current_leader
'
]:
while
Tru
e
:
#
while
"REQUEST_LEAD finish" not in decoded_messag
e:
response
=
f
"
LEADER:
{
shared_data
[
'
current_leader
'
]
}
"
.
encode
()
time
.
sleep
(
2
)
#wait before sending response that client can prepare for answer
server_socket
.
sendto
(
response
,
(
broadcast_ip
,
broadcast_port
))
...
...
@@ -82,9 +82,9 @@ def start_election(queue, shared_data):
while
time
.
time
()
<
timeout
:
try
:
message
=
queue
.
get
(
timeout
=
1
)
#waits 1 sec for a message
if
shared_data
[
'
server_id
'
]
==
sender_uuid
:
continue
el
if
"
START_ELECTION
"
in
message
:
#
if shared_data['server_id']==sender_uuid:
#
continue
if
"
START_ELECTION
"
in
message
:
sender_uuid
=
message
.
split
(
"
:
"
)[
1
]
active_servers
[
sender_uuid
]
=
time
.
time
()
print
(
f
"
Received UUID for election:
{
sender_uuid
}
"
)
...
...
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