我有这个服务器和客户端('Raspberry pis')。现在我必须从redis db读取服务器和客户端并获取消息并在前端UI中显示它。我正在使用DASH框架工作。如何实现应用程序服务器并阅读实时更新enter image description here 像这张照片中的东西,我没有使用芹菜和烧瓶。
import time
from mmnet.server import Server
BROKER = {"address": "10.0.10.1",
"port": 6379,
"db": 0}
# Create a new server instance. Pass it a dictionary with the connection details.
server = Server(BROKER)
# Tell the server which devices to expect. A combination of module + device is unique.
server.expect('Module1', 'Device1')
# The server waits for all expected devices to connect and calls their initialization function.
server.init()
# Execute a remote function in the given device with the given parameters. The result of
# this query will be returned by the function. This call is BLOCKING, so it will stop on the server
# until the function call finishes on the client
result = server.execute_function('Module1', 'Device1', 'move_to', 10, 50, 100, value=True, test="yes please")
# The server runs with a daemon thread, so make sure your program does not terminate!
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
# Always close the server at the end!
server.close()
import time
from mmnet.client import Client
BROKER = {"address": "10.0.10.1",
"port": 6379,
"db": 0}
def move_to(x, y, z, value="abc", test="def"):
return str(x) + str(y) + str(z) + value + test
def init_device():
pass
# Create a new client instance
client = Client(BROKER, 'Module1', 'Device1')
# Register your available functions
client.register_action('move_to', move_to)
# Notify the server we are ready to be initialized
client.init(init_device)
# The clients runs with a daemon thread, so make sure your program does not terminate!
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
# Always close the client at the end!
client.close()