Commit e994606d authored by Samuel Kemmler's avatar Samuel Kemmler
Browse files

Change server.py

parent 7c75c32c
#
# Hello World server in Python
# Binds REP socket to tcp://*:5555
# Expects b"Hello" from client, replies with b"World"
#
import time
import zmq
import json
import matplotlib.pyplot as plt
import time
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:5555")
while True:
# Wait for next request from client
message = socket.recv()
print("Received request: %s" % message)
# listen for requests
message = socket.recv().decode("ascii")
if message == "jacobi_request":
# create dictionary for parameters
iterations = 10
n_unknowns = 10
params = {}
params["n_unknowns"] = n_unknowns
# send parameters to client
print("Sending parameters for jacobi_request...")
socket.send(json.dumps(params).encode("ascii"))
# receive initial domain
message = socket.recv().decode("ascii").split("-")
message = [float(x) for x in message]
x_axis = [x for x in range(n_unknowns)]
plt.close()
plt.ion()
fig = plt.figure()
ax = fig.add_subplot(111)
line1, = ax.plot(x_axis, message)
# Do some 'work'
time.sleep(1)
for i in range(iterations):
# ask for next update of the unknowns and update plot
socket.send(b"next")
message = socket.recv().decode("ascii").split("-")
message = [float(x) for x in message]
line1.set_ydata(message)
fig.canvas.draw()
fig.canvas.flush_events()
time.sleep(0.5)
# Send reply back to client
socket.send(b"World")
socket.send(b"done")
else:
print("Invalid request message.")
socket.send(b"invalid")
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