class TestPush(object): def setup(self): self.url_tcp = 'tcp://0.0.0.0:9823/push' self.url_udp = 'udp://0.0.0.0:9823/push' self.node1 = Node() self.node1.serve(self.url_tcp) self.node1.serve(self.url_udp) self.node1.mirror() self.node2 = Node() def teardown(self): self.node2.shutdown() self.node1.shutdown() def test_tcp_push(self): proxy = self.node2.target(self.url_tcp) proxy.push('test1') assert self.node1.get() == b'test1' def test_udp_push(self): proxy = self.node2.target(self.url_tcp, self.url_udp, NLT_DGRAM) proxy.push('test2') assert self.node1.get() == b'test2'
''' Push/pull using RPC ''' from pyroute2.rpc import Node # create the first endpoint, serve two sockets node1 = Node() node1.serve('tcp://0.0.0.0:9824/push') node1.mirror() # create the second endpoint, connect via TCP node2 = Node() proxy1 = node2.target('tcp://0.0.0.0:9824/push') proxy1.push('hello, world!') # wait the message on the first endpoint print('waiting message from client') msg = node1.get() print(msg) node2.shutdown() node1.shutdown()
''' Push/pull using RPC ''' from pyroute2.rpc import Node # create the first endpoint, serve two sockets ioc1 = Node() ioc1.serve('tcp://0.0.0.0:9824/push') ioc1.mirror() # create the second endpoint, connect via TCP ioc2 = Node() proxy1 = ioc2.target('tcp://0.0.0.0:9824/push') proxy1.push('hello, world!') # wait the message on the first endpoint print('waiting message from client') msg = ioc1.get() print(msg) ioc2.shutdown() ioc1.shutdown()