#!/usr/bin/env python import sys import json import numpy as np import time sys.path.append('../../build') sys.path.append('../../build/swig') import quickmsg_py if __name__=='__main__': # By default, qm uses whatever interface it finds finds first. # this should be tailored to network configuration iface = "" quickmsg_py.init("test_py_pub", iface) p = quickmsg_py.Publisher('chatter') for i in xrange(10): if not quickmsg_py.ok(): break some_msg = json.dumps({'important_matrix':np.random.rand(4,4).tolist()}) print 'publishing', some_msg p.publish(some_msg) time.sleep(0.5)
#!/usr/bin/env python import sys import time # Assumes we're running from the test/python dir sys.path.append('../../build') sys.path.append('../../build/swig') import quickmsg_py if __name__=='__main__': # By default, qm uses whatever interface it finds finds first. # this should be tailored to network configuration iface = "" quickmsg_py.init("test_py_client", iface) c = quickmsg_py.Client('hello') req_msg = "Hello" for i in xrange(10): print 'Python client requesting:', req_msg resp_msg = c.calls(req_msg) print "Service replied:", resp_msg time.sleep(0.5) del c
#!/usr/bin/env python import os import sys import time # Assumes we're running from the test/python dir sys.path.append('../../build') sys.path.append('../../build/swig') import quickmsg_py class ServiceImpl(quickmsg_py.Service): def __init__(self, *args, **kwargs): super(ServiceImpl, self).__init__(*args, **kwargs) self.msg_count = 0 def service_impl(self, req): print 'Python inherited service callback' print 'Request:', req self.msg_count += 1 return "World {0}".format(self.msg_count) if __name__ == '__main__': quickmsg_py.init("test_py_service") svc = ServiceImpl('hello') svc.spin() del svc
#!/usr/bin/env python import sys import json import numpy as np import time sys.path.append('../../build') sys.path.append('../../build/swig') import quickmsg_py class SubscriberImpl(quickmsg_py.AsyncSubscriber): def __init__(self, *args, **kwargs): super(SubscriberImpl, self).__init__(*args, **kwargs) def subscriber_impl(self, msg): print 'Python inherited subscriber callback' print 'got message', msg.msg if __name__=='__main__': quickmsg_py.init("test_py_sub") s = SubscriberImpl('chatter') s.spin()
#!/usr/bin/env python import sys import json import numpy as np import time sys.path.append('../../build') sys.path.append('../../build/swig') import quickmsg_py class SubscriberImpl(quickmsg_py.AsyncSubscriber): def __init__(self, *args, **kwargs): super(SubscriberImpl, self).__init__(*args, **kwargs) def subscriber_impl(self, msg): print 'Python inherited subscriber callback' print 'got message', msg.msg if __name__ == '__main__': quickmsg_py.init("test_py_sub") s = SubscriberImpl('chatter') s.spin()
#!/usr/bin/env python import os import sys import time # Assumes we're running from the test/python dir sys.path.append('../../build') sys.path.append('../../build/swig') import quickmsg_py class ServiceImpl(quickmsg_py.Service): def __init__(self, *args, **kwargs): super(ServiceImpl, self).__init__(*args, **kwargs) self.msg_count = 0 def service_impl(self, req): print 'Python inherited service callback' print 'Request:', req self.msg_count += 1 return "World {0}".format(self.msg_count) if __name__=='__main__': quickmsg_py.init("test_py_service") svc = ServiceImpl('hello') svc.spin() del svc
#!/usr/bin/env python import sys import time # Assumes we're running from the test/python dir sys.path.append('../../build') sys.path.append('../../build/swig') import quickmsg_py if __name__ == '__main__': # By default, qm uses whatever interface it finds finds first. # this should be tailored to network configuration iface = "" quickmsg_py.init("test_py_client", iface) c = quickmsg_py.Client('hello') req_msg = "Hello" for i in xrange(10): print 'Python client requesting:', req_msg resp_msg = c.calls(req_msg) print "Service replied:", resp_msg time.sleep(0.5) del c