2016-10-02 15:19:51 +00:00
|
|
|
# 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
|
2016-10-03 04:15:33 +00:00
|
|
|
ts.publish('test', content)
|
2016-10-02 15:19:51 +00:00
|
|
|
sleep(2)
|