1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#!/usr/bin/env python
from pyliblo3 import *
import time
class MyServer(ServerThread):
def __init__(self, port=1234):
ServerThread.__init__(self, port)
@make_method('/foo', 'ifs')
def foo_callback(self, path, args):
i, f, s = args
print(f"Received message '{path}' with arguments: {i=}, {f=}, {s=}")
@make_method(None, None)
def fallback(self, path, args):
print(f"received unknown message '{path}' with {args=}")
server = MyServer()
server.start()
print(f"Server started in its own thread, send messages to {server.port}. Use CTRL-C to stop")
while True:
send(("127.0.0.0", server.port), "/foo", 10, 1.5, "bar")
send(("127.0.0.0", server.port), "/unknown", (3, 4))
time.sleep(1)
|