本文整理汇总了Python中socketserver.UDPServer方法的典型用法代码示例。如果您正苦于以下问题:Python socketserver.UDPServer方法的具体用法?Python socketserver.UDPServer怎么用?Python socketserver.UDPServer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socketserver
的用法示例。
在下文中一共展示了socketserver.UDPServer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_UDPServer
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import UDPServer [as 别名]
def test_UDPServer(self):
self.run_server(socketserver.UDPServer,
socketserver.DatagramRequestHandler,
self.dgram_examine)
示例2: __init__
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import UDPServer [as 别名]
def __init__(self, address):
socketserver.UDPServer.__init__(self, address, RequestHandlerUdp)
示例3: setUp
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import UDPServer [as 别名]
def setUp(self):
self.server = socketserver.UDPServer(('127.0.0.1', 2003), TestHandler)
self.server.timeout = 1.0
示例4: server_bind
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import UDPServer [as 别名]
def server_bind(self):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
# UDPServer is old-style class so can't use super
socketserver.UDPServer.server_bind(self)
示例5: __init__
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import UDPServer [as 别名]
def __init__(self, values={}, callback=None):
socketserver.UDPServer.__init__(
self, ('0.0.0.0', 53), RequestHandler
)
if callback is None:
self.getRecord = self._getRecord
else:
self.getRecord = callback
self.values = values
示例6: test_logging
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import UDPServer [as 别名]
def test_logging(self):
"""
Test logging.
"""
messages = []
class SyslogHandler(socketserver.BaseRequestHandler):
"""
Save received messages.
"""
def handle(self):
messages.append(self.request[0].strip().decode())
syslog = socketserver.UDPServer(('0.0.0.0', 0), SyslogHandler)
try:
threading.Thread(target=syslog.serve_forever).start()
env = os.environ.copy()
env['SYSLOG_SERVER'] = syslog.server_address[0]
env['SYSLOG_PORT'] = str(syslog.server_address[1])
env['SYSLOG_PROTO'] = 'udp'
mydir = os.path.dirname(__file__)
supervisor = subprocess.Popen(
['supervisord', '-c', os.path.join(mydir, 'supervisord.conf')],
env=env,
)
try:
sleep(3)
pid = subprocess.check_output(
['supervisorctl', 'pid', 'messages']
).decode().strip()
sleep(8)
self.assertEqual(
list(map(strip_volatile, messages)),
['<14>DATE HOST messages[{pid}]: Test {i} \n\x00'.format(
pid=pid,
i=i)
for i in range(4)]
)
finally:
supervisor.terminate()
finally:
syslog.shutdown()
示例7: open
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import UDPServer [as 别名]
def open(self, staged=False):
"""
open the DNS server and listen for connections
:param staged: should we stage first?
:return: True if successfull
"""
if not self.validate_options():
return False
# reset all internal values
self.conn = None
self.server = None
self.staged = staged
self.currentstagenum = 0
self.currentnum = -1
self.senddataqueue = DataQueue()
self.recvdataqueue = DataQueue()
self.progress = None
self.maxstagenum = None
self.laststagepart = None
self.lastpart = None
if not staged:
self.currentstagenum = -1
else:
self.currentstagenum = 0
# mark backchannel to us from each DnsHandler instance
DnsHandler.transport = self
lparams = (self.options['LHOST']['Value'], int(self.options['LPORT']['Value']))
try:
self.server = socketserver.UDPServer(lparams, DnsHandler)
except PermissionError as e:
print_error("Could not open DNS server on {}:{}: {}".format(lparams[0], lparams[1],
str(e)))
return False
threading.Thread(target=self.server.serve_forever).start()
print_message("DNS listening on {}:{}".format(lparams[0], lparams[1]))
return True