本文整理汇总了Python中SocketServer.UDPServer.handle_request方法的典型用法代码示例。如果您正苦于以下问题:Python UDPServer.handle_request方法的具体用法?Python UDPServer.handle_request怎么用?Python UDPServer.handle_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketServer.UDPServer
的用法示例。
在下文中一共展示了UDPServer.handle_request方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NodeReferee
# 需要导入模块: from SocketServer import UDPServer [as 别名]
# 或者: from SocketServer.UDPServer import handle_request [as 别名]
class NodeReferee(object):
def __init__(self, verbose=False, name="NodeReferee"):
rospy.init_node(name, anonymous=False)
rospy.loginfo("Stop referee by pressing CTRL + C")
self.verbose = verbose
if verbose:
rospy.loginfo("Being verbose")
rospy.on_shutdown(self.shutdown)
# Publisher
self.topic = rospy.Publisher('soccer/referee', Bool, queue_size=10)
# UDP Server with callback
addr = ("", 4711)
rospy.loginfo("listening on %s:%s" % addr)
self.server = UDPServer(addr, Handler)
self.server.timeout = 5
self.server.callback = self.publish
# Stoppable serve_forever workaround =)
self.run = True
while(self.run):
self.server.handle_request()
def publish(self, data, client_address):
# By definition:
# 1 => keep going / start
# 0 => stop
running = (data == "1")
if self.verbose:
rospy.loginfo("Received '%s' from %s considered as %s" % (data, client_address, str(running)))
self.topic.publish(running)
def shutdown(self):
rospy.loginfo("Shutting down ... (can take up to %d seconds)" % self.server.timeout)
self.run = False