Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs425_distributed_system_mp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
hangxie2
cs425_distributed_system_mp
Commits
db0e8964
Commit
db0e8964
authored
3 years ago
by
Hang
Browse files
Options
Downloads
Patches
Plain Diff
fast push
parent
09764cfe
No related branches found
No related tags found
1 merge request
!10
MP3 Log Version Ready
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sample_test/src/client.py
+13
-2
13 additions, 2 deletions
sample_test/src/client.py
with
13 additions
and
2 deletions
sample_test/src/client.py
+
13
−
2
View file @
db0e8964
...
...
@@ -9,6 +9,8 @@ import socket
PORT
=
8888
CURRNT_SERVER
=
socket
.
gethostbyname
(
socket
.
gethostname
())
ADDR
=
(
CURRNT_SERVER
,
PORT
)
SERVER_ID_TO_IP_MAPPING
=
{}
IP_TO_SERVER_ID_MAPPING
=
{}
def
parse_config
(
config_path
:
str
)
->
dict
:
...
...
@@ -30,10 +32,11 @@ def pick_coordinator(servers: dict):
def
connect
(
coordinator_info
:
tuple
):
coordinator_address
=
coordinator_info
[
1
][
SERVER_ADDRESS
]
coordinator_ip_address
=
SERVER_ID_TO_IP_MAPPING
[
coordinator_info
[
SERVER_IDENTIFIER
]]
# coordinator_address = coordinator_info[1][SERVER_ADDRESS]
coordinator_port_number
=
coordinator_info
[
1
][
SERVER_PORT
]
client
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
address
=
(
coordinator_address
,
coordinator_port_number
)
address
=
(
coordinator_
ip_
address
,
coordinator_port_number
)
pprint
(
f
'
[connect] - client connect to address
{
address
}
'
)
client
.
connect
(
address
)
return
client
...
...
@@ -58,10 +61,18 @@ def send_operation(operation_str, socket):
socket
.
sendall
(
msg
)
def
map_hostname_to_ip
(
servers
):
for
server_id
,
server
in
servers
.
items
():
SERVER_ID_TO_IP_MAPPING
[
server_id
]
=
socket
.
gethostbyname
(
server
[
SERVER_ADDRESS
])
IP_TO_SERVER_ID_MAPPING
[
SERVER_ID_TO_IP_MAPPING
[
server_id
]]
=
server_id
if
__name__
==
'
__main__
'
:
client_name
=
sys
.
argv
[
1
]
config_path
=
sys
.
argv
[
2
]
servers
=
parse_config
(
config_path
)
map_hostname_to_ip
(
servers
)
coordinator_info
=
pick_coordinator
(
servers
)
client_to_coordinator_socket
=
connect
(
coordinator_info
)
pprint
(
'
[client_to_coordinator_socket] CONNECT SUCCESS!
'
)
...
...
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