本文整理汇总了Python中xmlrpclib.ServerProxy.requestTopic方法的典型用法代码示例。如果您正苦于以下问题:Python ServerProxy.requestTopic方法的具体用法?Python ServerProxy.requestTopic怎么用?Python ServerProxy.requestTopic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xmlrpclib.ServerProxy
的用法示例。
在下文中一共展示了ServerProxy.requestTopic方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: requestTopic
# 需要导入模块: from xmlrpclib import ServerProxy [as 别名]
# 或者: from xmlrpclib.ServerProxy import requestTopic [as 别名]
def requestTopic(self, topic):
code, statusMessage, publishers = self.master.registerSubscriber(
self.callerId, topic, lookupTopicType(topic)[0], self.callerApi
)
assert code == 1, (code, statusMessage)
assert len(publishers) == 1, (topic, publishers) # i.e. fails if publisher is not ready now
print publishers
publisher = ServerProxy(publishers[0])
code, statusMessage, protocolParams = publisher.requestTopic(self.callerId, topic, [["TCPROS"]])
assert code == 1, (code, statusMessage)
assert len(protocolParams) == 3, protocolParams
print code, statusMessage, protocolParams
hostPortPair = (protocolParams[1], protocolParams[2])
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # TCP
soc.connect(hostPortPair)
soc.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
soc.setblocking(0)
soc.settimeout(SOCKET_TIMEOUT)
header = prefix4BytesLen(
prefix4BytesLen("callerid=" + self.callerId)
+ prefix4BytesLen("topic=" + topic)
+ prefix4BytesLen("type=" + lookupTopicType(topic)[0])
+ prefix4BytesLen("md5sum=" + lookupTopicType(topic)[1])
+ ""
)
soc.send(header)
return soc
示例2: len
# 需要导入模块: from xmlrpclib import ServerProxy [as 别名]
# 或者: from xmlrpclib.ServerProxy import requestTopic [as 别名]
code, statusMessage, topicTypes = master.getTopicTypes(caller_id)
assert code == 1, code
print "---"
print "topicTypes:"
for t in topicTypes:
print t
print "---"
code, statusMessage, publishers = master.registerSubscriber(caller_id, topic, topic_type, caller_api)
assert code == 1, code
assert len(publishers) == 1, publishers # i.e. fails if publisher is not ready now
print publishers
publisher = ServerProxy(publishers[0].replace("martind-ThinkPad-R60", "192.168.0.13")) # "pseudo DNS"
code, statusMessage, protocolParams = publisher.requestTopic(caller_id, topic, [["TCPROS"]])
assert code == 1, code
assert len(protocolParams) == 3, protocolParams
print code, statusMessage, protocolParams
print protocolParams
# hostPortPair = ( "192.168.0.13", protocolParams[2] )
hostPortPair = (protocolParams[1], protocolParams[2])
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # TCP
soc.connect(hostPortPair)
soc.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
soc.setblocking(0)
soc.settimeout(3.0)
示例3: ServerProxy
# 需要导入模块: from xmlrpclib import ServerProxy [as 别名]
# 或者: from xmlrpclib.ServerProxy import requestTopic [as 别名]
roslib.load_manifest("ros_monitor")
import os, sys
import rospy
from xmlrpclib import ServerProxy
import rosgraph
target_node = sys.argv[1]
rospy.init_node("introspecter", anonymous=True)
my_caller_id = rospy.get_name()
print "Caller ID: %s" % my_caller_id
# ask the master for this node's API URI
master = rosgraph.Master(my_caller_id)
node_api_uri = master.lookupNode(target_node)
print "Node URI: %s" % node_api_uri
# connect to the node and ask what it pubishes
ps = ServerProxy(node_api_uri)
(code, status_msg, topic_list) = ps.getPublications(my_caller_id)
print "=== Topics:"
print topic_list
# try to subscribe to each topic
for topic_name, topic_type in topic_list:
print "Subscribing to topic %s with type %s" % (topic_name, topic_type)
(code, status_msg, protocol_params) = ps.requestTopic(my_caller_id, topic_name, [["TCPROS"]])
print protocol_params