當前位置: 首頁>>代碼示例>>Python>>正文


Python SocketServer.UDPServer方法代碼示例

本文整理匯總了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()') 
開發者ID:masmu,項目名稱:pulseaudio-dlna,代碼行數:24,代碼來源:listener.py

示例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) 
開發者ID:fabio-d,項目名稱:honeypot,代碼行數:20,代碼來源:testrun.py

示例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() 
開發者ID:barronwaffles,項目名稱:dwc_network_server_emulator,代碼行數:22,代碼來源:gamespy_natneg_server.py

示例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) 
開發者ID:GoSecure,項目名稱:break-fast-serial,代碼行數:10,代碼來源:dnschef.py

示例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) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:test_socketserver.py

示例6: __init__

# 需要導入模塊: import SocketServer [as 別名]
# 或者: from SocketServer import UDPServer [as 別名]
def __init__(self, address):
        socketserver.UDPServer.__init__(self, address, RequestHandlerUdp) 
開發者ID:avocado-framework,項目名稱:avocado-vt,代碼行數:4,代碼來源:syslog_server.py

示例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() 
開發者ID:openstack,項目名稱:designate,代碼行數:11,代碼來源:statsd_mock_server.py

示例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) 
開發者ID:poliva,項目名稱:ggposrv,代碼行數:5,代碼來源:ggposrv.py

示例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 
開發者ID:Tr3jer,項目名稱:dnsAutoRebinding,代碼行數:6,代碼來源:main.py

示例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) 
開發者ID:fireeye,項目名稱:flare-fakenet-ng,代碼行數:6,代碼來源:DNSListener.py

示例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() 
開發者ID:opensec-cn,項目名稱:vtest,代碼行數:5,代碼來源:vtest.py

示例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) 
開發者ID:paranoidninja,項目名稱:piSociEty,代碼行數:6,代碼來源:DNS.py

示例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() 
開發者ID:infoxchange,項目名稱:supervisor-logging,代碼行數:54,代碼來源:test_supervisor_logging.py


注:本文中的SocketServer.UDPServer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。