Commit 7755e2ff authored by Samuel Kemmler's avatar Samuel Kemmler
Browse files

Change client.py

parent e994606d
#
# 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"))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment