本文整理汇总了Python中SocketServer.UDPServer.server_close方法的典型用法代码示例。如果您正苦于以下问题:Python UDPServer.server_close方法的具体用法?Python UDPServer.server_close怎么用?Python UDPServer.server_close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketServer.UDPServer
的用法示例。
在下文中一共展示了UDPServer.server_close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __receiver_thread
# 需要导入模块: from SocketServer import UDPServer [as 别名]
# 或者: from SocketServer.UDPServer import server_close [as 别名]
class ALPSUDPConnection:
def __receiver_thread(self, request, client_address, server):
message = request[0]
if callable(self.receiver_func_callback):
self.receiver_func_callback(self, client_address, message)
# print client_address
def __init__(self, ip, port, receiver_func=None, background=False, use_threading=True):
self.ip_string = ip
self.port = port
self.receiver_func_callback = receiver_func
self.background = background
if use_threading:
self.udpconnection = ThreadingUDPServer((self.ip_string, self.port), self.__receiver_thread)
else:
self.udpconnection = UDPServer((self.ip_string, self.port), self.__receiver_thread)
self.udpconnection.allow_reuse_address = True
# self.__objname = inspect.stack()[1][-2][0].split('=')[0].strip()
def __serve_forever(self):
try:
self.udpconnection.serve_forever()
except:
pass
def bind(self, thread_name="UDPConnection Thread"):
self.udpsock_thread = ALPSThread(threadfunc=self.__serve_forever, threadname=thread_name)
self.udpsock_thread.setDaemon(not self.background)
self.udpsock_thread.start()
def send(self, client_address, message, error_except=True):
if type(client_address) is tuple:
addr_tuple = client_address
else:
addr_tuple = (client_address.split(':')[0], int(client_address.split(':')[1]))
if not error_except:
return self.udpconnection.socket.sendto(message, addr_tuple)
try:
self.udpconnection.socket.sendto(message, addr_tuple)
except Exception as e:
ALPSDebug.alps_error(e, '\n', inspect.getframeinfo((inspect.currentframe().f_back)))
return False
return True
def close(self):
self.udpconnection.server_close()
示例2: server_close
# 需要导入模块: from SocketServer import UDPServer [as 别名]
# 或者: from SocketServer.UDPServer import server_close [as 别名]
def server_close(self):
UDPServer.server_close(self)
self.db.stop()