Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Distributed-for-FL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
LSDS
Teaching
Continuum-Computing
Distributed-for-FL
Commits
99feeae8
Commit
99feeae8
authored
1 year ago
by
mohamad.moussa
Browse files
Options
Downloads
Patches
Plain Diff
Update sock.py
parent
75afcca8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Local-Without-Prediction/sock.py
+20
-23
20 additions, 23 deletions
Local-Without-Prediction/sock.py
with
20 additions
and
23 deletions
Local-Without-Prediction/sock.py
+
20
−
23
View file @
99feeae8
...
...
@@ -6,12 +6,16 @@ import select
import
os
import
logging
NB_ITERATIONS
=
20
# Setup logging
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
'
%(asctime)s %(levelname)s %(message)s
'
,
handlers
=
[
logging
.
StreamHandler
(
sys
.
stdout
)])
logger
=
logging
.
getLogger
(
__name__
)
def
send_Message
(
sock
,
src
,
dest
,
msg
):
sock
.
connect
((
dest
,
base_port
))
data
=
json
.
dumps
((
msg
,
src
))
sock
.
send
(
data
.
encode
())
def
mainProg
(
neighbors
,
rank
,
base_port
,
ip_address
):
c
=
0
iteration
=
0
...
...
@@ -24,17 +28,13 @@ def mainProg(neighbors, rank, base_port, ip_address):
time
.
sleep
(
10
)
logger
.
info
(
f
"
Server
{
rank
}
listening on
{
ip_address
}
and port
{
base_port
}
"
)
while
iteration
<
NB_ITERATIONS
:
if
iteration
<
3
:
while
True
:
for
neighbor
in
neighbors
:
try
:
neighbor_ip
=
f
"
node
{
neighbor
}
"
# Use Docker service name
neighbor_ip
=
f
"
node
{
neighbor
}
"
client_socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
client_socket
.
connect
((
neighbor_ip
,
base_port
))
message
=
"
REQUEST_WEIGHT
"
data
=
json
.
dumps
((
message
,
rank
))
client_socket
.
send
(
data
.
encode
())
logger
.
info
(
f
"
Rank
{
rank
}
sent
{
message
}
to
{
neighbor
}
at iteration
{
iteration
}
"
)
send_Message
(
client_socket
,
rank
,
neighbor_ip
,
"
REQUEST_WEIGHT
"
)
logger
.
info
(
f
"
Rank
{
rank
}
sent REQUEST_WEIGHT to
{
neighbor
}
at iteration
{
iteration
}
"
)
time
.
sleep
(
3
)
client_socket
.
close
()
except
ConnectionRefusedError
as
e
:
...
...
@@ -53,12 +53,9 @@ def mainProg(neighbors, rank, base_port, ip_address):
if
message_rcvd
==
"
REQUEST_WEIGHT
"
:
try
:
sender_ip
=
f
"
node
{
sender
}
"
# Use Docker service name
sender_ip
=
f
"
node
{
sender
}
"
cl_socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
cl_socket
.
connect
((
sender_ip
,
base_port
))
message
=
"
WEIGHTS
"
data
=
json
.
dumps
((
message
,
rank
))
cl_socket
.
send
(
data
.
encode
())
send_Message
(
cl_socket
,
rank
,
sender_ip
,
"
WEIGHTS
"
)
time
.
sleep
(
3
)
cl_socket
.
close
()
except
ConnectionRefusedError
as
e
:
...
...
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