vnpy/vn.rpc/testServer.py
chenxy123 f538e6aa12 增加vn.rpc模块功能:
1. 提供RpcObject用于兼容不同的序列化工具
2. 提供广播数据时的主题筛选功能,实现数据筛选的工作由python层下放到zmq c++底层,提高效率
2016-10-03 12:15:33 +08:00

37 lines
952 B
Python

# encoding: UTF-8
from time import sleep, time
from vnrpc import RpcServer
########################################################################
class TestServer(RpcServer):
"""测试服务器"""
#----------------------------------------------------------------------
def __init__(self, repAddress, pubAddress):
"""Constructor"""
super(TestServer, self).__init__(repAddress, pubAddress)
self.register(self.add)
#----------------------------------------------------------------------
def add(self, a, b):
"""测试函数"""
print 'receiving: %s, %s' % (a,b)
return a + b
if __name__ == '__main__':
repAddress = 'tcp://*:2014'
pubAddress = 'tcp://*:0602'
ts = TestServer(repAddress, pubAddress)
ts.start()
while 1:
content = 'current server time is %s' % time()
print content
ts.publish('test', content)
sleep(2)