Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Samuel Kemmler
FA Server Client
Commits
7755e2ff
Commit
7755e2ff
authored
Sep 07, 2021
by
Samuel Kemmler
Browse files
Change client.py
parent
e994606d
Changes
1
Show whitespace changes
Inline
Side-by-side
client.py
View file @
7755e2ff
#
# Hello World client in Python
# Connects REQ socket to tcp://localhost:5555
# Sends "Hello" to server, expects "World" back
#
import
zmq
import
json
import
random
def
jacobi_iteration
(
u
):
for
i
in
range
(
1
,
len
(
u
)
-
1
):
u
[
i
]
=
0.5
*
(
u
[
i
-
1
]
+
u
[
i
+
1
])
context
=
zmq
.
Context
()
# Socket to talk to server
print
(
"Connecting to hello world server…"
)
socket
=
context
.
socket
(
zmq
.
REQ
)
socket
.
connect
(
"tcp://192.168.2.110:5555"
)
# Do 10 requests, waiting each time for a response
for
request
in
range
(
10
):
print
(
"Sending request %s …"
%
request
)
socket
.
send
(
b
"Hello"
)
print
(
"Requesting parameters…"
)
socket
.
send
(
b
"jacobi_request"
)
message
=
socket
.
recv
().
decode
(
"ascii"
)
params
=
json
.
loads
(
message
)
# initialize domain
u
=
[
random
.
random
()
for
i
in
range
(
params
[
"n_unknowns"
])]
u
[
0
]
=
0.0
u
[
len
(
u
)
-
1
]
=
0.0
socket
.
send
(
"-"
.
join
(
str
(
x
)
for
x
in
u
).
encode
(
"ascii"
))
# Get the reply.
message
=
socket
.
recv
()
while
True
:
# if requested, perform jacobi iteration and send result
message
=
socket
.
recv
().
decode
(
"ascii"
)
if
message
!=
"next"
:
break
jacobi_iteration
(
u
)
socket
.
send
(
"-"
.
join
(
str
(
x
)
for
x
in
u
).
encode
(
"ascii"
))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment