vnpy/examples/simple_rpc/test_server.py

41 lines
778 B
Python
Raw Permalink Normal View History

2019-04-02 09:07:10 +00:00
from __future__ import print_function
from __future__ import absolute_import
from time import sleep, time
from vnpy.rpc import RpcServer
2019-04-02 09:07:10 +00:00
class TestServer(RpcServer):
"""
Test RpcServer
"""
def __init__(self):
2019-04-02 09:07:10 +00:00
"""
Constructor
"""
super(TestServer, self).__init__()
2019-04-02 09:07:10 +00:00
self.register(self.add)
def add(self, a, b):
"""
Test function
"""
print(f"receiving:{a} {b}")
2019-04-02 09:07:10 +00:00
return a + b
if __name__ == "__main__":
rep_address = "tcp://*:2014"
pub_address = "tcp://*:4102"
2019-04-02 09:07:10 +00:00
ts = TestServer()
ts.start(rep_address, pub_address)
2019-04-02 09:07:10 +00:00
while 1:
content = f"current server time is {time()}"
2019-04-02 09:07:10 +00:00
print(content)
ts.publish("test", content)
2019-04-02 09:07:10 +00:00
sleep(2)