本文整理汇总了Python中SocketServer.UDPServer方法的典型用法代码示例。如果您正苦于以下问题:Python SocketServer.UDPServer方法的具体用法?Python SocketServer.UDPServer怎么用?Python SocketServer.UDPServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketServer
的用法示例。
在下文中一共展示了SocketServer.UDPServer方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import UDPServer [as 别名]
def run(self, ttl=None):
if self.DISABLE_SSDP_LISTENER:
return
self.allow_reuse_address = True
SocketServer.UDPServer.__init__(
self, (self.host or '', self.SSDP_PORT), SSDPHandler)
self.socket.setsockopt(
socket.IPPROTO_IP,
socket.IP_ADD_MEMBERSHIP,
self._multicast_struct(self.SSDP_ADDRESS))
self.socket.setsockopt(
socket.IPPROTO_IP,
socket.IP_MULTICAST_TTL,
self.SSDP_TTL)
if ttl:
GObject.timeout_add(ttl * 1000, self.shutdown)
setproctitle.setproctitle('ssdp_listener')
self.serve_forever(self)
logger.info('SSDPListener.run()')
示例2: run_udp
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import UDPServer [as 别名]
def run_udp(realport, fakeport, handler):
class SingleUDPHandler(SocketServer.BaseRequestHandler):
def handle(self):
srcaddr, srcport = self.client_address
print("Packet from {}:{}".format(srcaddr, srcport))
handler(self.request[1], self.request[0], self.client_address, fakeport)
class SimpleServer(SocketServer.ThreadingMixIn, SocketServer.UDPServer):
daemon_threads = True
def __init__(self, server_address, RequestHandlerClass):
SocketServer.UDPServer.__init__(self, server_address, RequestHandlerClass)
server = SimpleServer(('127.0.0.1', realport), SingleUDPHandler)
try:
server.serve_forever()
except KeyboardInterrupt:
sys.exit(0)
示例3: __init__
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import UDPServer [as 别名]
def __init__(self,
server_address=dwc_config.get_ip_port('GameSpyNatNegServer'),
RequestHandlerClass=GameSpyNatNegUDPServerHandler,
bind_and_activate=True):
SocketServer.UDPServer.__init__(self,
server_address,
RequestHandlerClass,
bind_and_activate)
self.session_list = {}
self.natneg_preinit_session = {}
self.secret_key_list = gs_utils.generate_secret_keys("gslist.cfg")
self.server_manager = GameSpyServerDatabase(
address=dwc_config.get_ip_port('GameSpyManager'),
authkey=""
)
self.server_manager.connect()
self.write_queue = Queue.Queue()
threading.Thread(target=self.write_queue_worker).start()
示例4: __init__
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import UDPServer [as 别名]
def __init__(self, server_address, RequestHandlerClass, nametodns, nameservers, ipv6, log):
self.nametodns = nametodns
self.nameservers = nameservers
self.ipv6 = ipv6
self.address_family = socket.AF_INET6 if self.ipv6 else socket.AF_INET
self.log = log
SocketServer.UDPServer.__init__(self,server_address,RequestHandlerClass)
示例5: test_UDPServer
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import UDPServer [as 别名]
def test_UDPServer(self):
self.run_server(SocketServer.UDPServer,
SocketServer.DatagramRequestHandler,
self.dgram_examine)
示例6: __init__
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import UDPServer [as 别名]
def __init__(self, address):
socketserver.UDPServer.__init__(self, address, RequestHandlerUdp)
示例7: main
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import UDPServer [as 别名]
def main():
args = parse_args()
fd = open(args.output_fname, 'a') if args.output_fname else None
StatsdMessageHandler._output_fd = fd
server = SocketServer.UDPServer(
(args.addr, args.port),
StatsdMessageHandler,
)
server.serve_forever()
示例8: __init__
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import UDPServer [as 别名]
def __init__(self, server_address, MyUDPHandler):
self.quarkqueue = {}
SocketServer.UDPServer.__init__(self, server_address, MyUDPHandler)
示例9: __init__
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import UDPServer [as 别名]
def __init__(self,options):
SocketServer.UDPServer.__init__(self, ('0.0.0.0', 53), self.sHandle)
self.timeout = 3
self.options = options
示例10: __init__
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import UDPServer [as 别名]
def __init__(self, server_address, config, logger, RequestHandlerClass):
self.config = config
self.logger = logger
SocketServer.UDPServer.__init__(self, server_address, RequestHandlerClass)
示例11: start
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import UDPServer [as 别名]
def start(self):
server = SocketServer.UDPServer(("0.0.0.0", 53), DNSUDPHandler)
server.serve_forever()
示例12: __init__
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import UDPServer [as 别名]
def __init__(self, server_address, RequestHandlerClass):
self.address_family = socket.AF_INET6 if DNSChef().ipv6 else socket.AF_INET
SocketServer.UDPServer.__init__(self,server_address,RequestHandlerClass)
示例13: 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()