当前位置: 首页>>代码示例>>Python>>正文


Python SocketServer.TCPServer方法代码示例

本文整理汇总了Python中SocketServer.TCPServer方法的典型用法代码示例。如果您正苦于以下问题:Python SocketServer.TCPServer方法的具体用法?Python SocketServer.TCPServer怎么用?Python SocketServer.TCPServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SocketServer的用法示例。


在下文中一共展示了SocketServer.TCPServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import TCPServer [as 别名]
def run(self):
        self.allow_reuse_address = True
        self.daemon_threads = True
        try:
            SocketServer.TCPServer.__init__(
                self, (self.ip or '', self.port), StreamRequestHandler)
        except socket.error:
            logger.critical(
                'The streaming server could not bind to your specified port '
                '({port}). Perhaps this is already in use? The application '
                'cannot work properly!'.format(port=self.port))
            sys.exit(1)

        signal.signal(signal.SIGTERM, self.shutdown)
        if self.proc_title:
            setproctitle.setproctitle(self.proc_title)
        self.serve_forever() 
开发者ID:masmu,项目名称:pulseaudio-dlna,代码行数:19,代码来源:streamserver.py

示例2: __init__

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import TCPServer [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.TCPServer.__init__(self,server_address,RequestHandlerClass) 
        
# Initialize and start the DNS Server 
开发者ID:GoSecure,项目名称:break-fast-serial,代码行数:12,代码来源:dnschef.py

示例3: __init__

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import TCPServer [as 别名]
def __init__(self, server_address, RequestHandlerClass, config):
            self.config = config
            SocketServer.TCPServer.__init__(self,server_address, RequestHandlerClass) 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:5,代码来源:httprelayserver.py

示例4: test_shutdown_request_called_if_verify_request_false

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import TCPServer [as 别名]
def test_shutdown_request_called_if_verify_request_false(self):
        # Issue #26309: BaseServer should call shutdown_request even if
        # verify_request is False

        class MyServer(SocketServer.TCPServer):
            def verify_request(self, request, client_address):
                return False

            shutdown_called = 0
            def shutdown_request(self, request):
                self.shutdown_called += 1
                SocketServer.TCPServer.shutdown_request(self, request)

        server = MyServer((HOST, 0), SocketServer.StreamRequestHandler)
        s = socket.socket(server.address_family, socket.SOCK_STREAM)
        s.connect(server.server_address)
        s.close()
        server.handle_request()
        self.assertEqual(server.shutdown_called, 1)
        close_server(server) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_socketserver.py

示例5: serve

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import TCPServer [as 别名]
def serve(port=PORT):
    '''Serves test XML files over HTTP'''
    
    # Make sure we serve from the tests' XML directory
    os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)),
                          'xml'))

    Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
    
    class TestServer(SocketServer.TCPServer):
        allow_reuse_address = True
    
    httpd = TestServer(("", PORT), Handler)
    
    print 'Serving test HTTP server at port', PORT

    httpd_thread = Thread(target=httpd.serve_forever)
    httpd_thread.setDaemon(True)
    httpd_thread.start() 
开发者ID:italia,项目名称:daf-recipes,代码行数:21,代码来源:xml_file_server.py

示例6: serve

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import TCPServer [as 别名]
def serve(port=PORT):
    '''Runs a CKAN-alike app (over HTTP) that is used for harvesting tests'''

    # Choose the directory to serve files from
    #os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)),
    #                      'mock_ckan_files'))

    class TestServer(SocketServer.TCPServer):
        allow_reuse_address = True

    httpd = TestServer(("", PORT), MockCkanHandler)

    print 'Serving test HTTP server at port', PORT

    httpd_thread = Thread(target=httpd.serve_forever)
    httpd_thread.setDaemon(True)
    httpd_thread.start() 
开发者ID:italia,项目名称:daf-recipes,代码行数:19,代码来源:mock_ckan.py

示例7: test_shutdown

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import TCPServer [as 别名]
def test_shutdown(self):
        # Issue #2302: shutdown() should always succeed in making an
        # other thread leave serve_forever().
        class MyServer(SocketServer.TCPServer):
            pass

        class MyHandler(SocketServer.StreamRequestHandler):
            pass

        threads = []
        for i in range(20):
            s = MyServer((HOST, 0), MyHandler)
            t = threading.Thread(
                name='MyServer serving',
                target=s.serve_forever,
                kwargs={'poll_interval':0.01})
            t.daemon = True  # In case this function raises.
            threads.append((t, s))
        for t, s in threads:
            t.start()
            s.shutdown()
        for t, s in threads:
            t.join() 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:25,代码来源:test_socketserver.py

示例8: handle_error

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import TCPServer [as 别名]
def handle_error(self, request, client_address):
        """Override TCPServer method

        Error message goes to __stderr__.  No error message if exiting
        normally or socket raised EOF.  Other exceptions not handled in
        server code will cause os._exit.

        """
        try:
            raise
        except SystemExit:
            raise
        except:
            erf = sys.__stderr__
            print>>erf, '\n' + '-'*40
            print>>erf, 'Unhandled server exception!'
            print>>erf, 'Thread: %s' % threading.currentThread().getName()
            print>>erf, 'Client Address: ', client_address
            print>>erf, 'Request: ', repr(request)
            traceback.print_exc(file=erf)
            print>>erf, '\n*** Unrecoverable, server exiting!'
            print>>erf, '-'*40
            os._exit(0)

#----------------- end class RPCServer -------------------- 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:27,代码来源:rpc.py

示例9: __init__

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import TCPServer [as 别名]
def __init__(self, server_address=('0.0.0.0', 1080), handler_class=SocksRequestHandler):
        LOG.info('SOCKS proxy started. Listening at port %d', server_address[1] )

        self.activeRelays = {}
        self.socksPlugins = {}
        SocketServer.TCPServer.allow_reuse_address = True
        SocketServer.TCPServer.__init__(self, server_address, handler_class)

        # Let's register the socksplugins plugins we have
        from impacket.examples.ntlmrelayx.servers.socksplugins import SOCKS_RELAYS

        for relay in SOCKS_RELAYS:
            LOG.info('Plugin %s loaded..' % relay.PLUGIN_NAME)
            self.socksPlugins[relay.getProtocolPort()] = relay

        # Let's create a timer to keep the connections up.
        self.__timer = RepeatedTimer(300.0, keepAliveTimer, self) 
开发者ID:eth0izzle,项目名称:cracke-dit,代码行数:19,代码来源:socksserver.py

示例10: run_tcp

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import TCPServer [as 别名]
def run_tcp(realport, fakeport, handler):
	class SingleTCPHandler(SocketServer.BaseRequestHandler):
		def handle(self):
			srcaddr, srcport = self.request.getpeername()
			print("Connection from {}:{}".format(srcaddr, srcport))
			handler(self.request, fakeport)

	class SimpleServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
		daemon_threads = True
		allow_reuse_address = True

		def __init__(self, server_address, RequestHandlerClass):
			SocketServer.TCPServer.__init__(self, server_address, RequestHandlerClass)

	server = SimpleServer(('127.0.0.1', realport), SingleTCPHandler)
	try:
		server.serve_forever()
	except KeyboardInterrupt:
		sys.exit(0) 
开发者ID:fabio-d,项目名称:honeypot,代码行数:21,代码来源:testrun.py

示例11: finish_request

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import TCPServer [as 别名]
def finish_request(self, request, client_address):
		self.sensor.alarm("Got TCP connection, raising alarm")
		return SocketServer.TCPServer.finish_request(self, request, client_address) 
开发者ID:SecPi,项目名称:SecPi,代码行数:5,代码来源:tcpportlistener.py

示例12: start_server

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import TCPServer [as 别名]
def start_server(self):

        if self.webserverStarted == False and self.CONTROLLER_SERVER_PATH != '':
            """Changing dir to the schedules dir."""
            web_dir = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', 'schedules'))
            os.chdir(web_dir)
            PORT = int(self.CONTROLLER_SERVER_PORT)
            class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):

                def log_message(self, format, *args):
                    return

            global httpd
            try:
                #print "Starting webserver at port: ", PORT
                # create the httpd handler for the simplehttpserver
                # we set the allow_reuse_address incase something hangs can still bind to port
                class ReusableTCPServer(SocketServer.TCPServer): allow_reuse_address=True
                # specify the httpd service on 0.0.0.0 (all interfaces) on port 80
                httpd = ReusableTCPServer(("0.0.0.0", PORT),MyHandler)
                # thread this mofo
                thread.start_new_thread(httpd.serve_forever,())
            # handle keyboard interrupts
            except KeyboardInterrupt:
                core.print_info("Exiting the SET web server...")
                httpd.socket.close()
            except socket.error, exc:
                print "Caught exception socket.error : %s" % exc 
            # handle the rest
            #except Exception:
            #    print "[*] Exiting the SET web server...\n"
            #    httpd.socket.close()
            self.webserverStarted = True 
开发者ID:justinemter,项目名称:pseudo-channel,代码行数:35,代码来源:PseudoDailyScheduleController.py

示例13: __init__

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import TCPServer [as 别名]
def __init__(self, file_uri, bind_host, request_host, port, handler=None):
        self.file_uri = file_uri
        self.file_path, self.file_name = os.path.split(self.file_uri)
        self.bind_host = bind_host
        self.request_host = request_host
        self.port = port
        self.handler = handler or DefaultRequestHandler

        os.chdir(self.file_path)
        SocketServer.TCPServer.__init__(
            self, (self.bind_host, self.port), self.handler) 
开发者ID:masmu,项目名称:pulseaudio-dlna,代码行数:13,代码来源:chromecast-beam.py

示例14: spawn

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import TCPServer [as 别名]
def spawn(env):
  PythonConsoleServer.env = env
  tcpserver = SocketServer.TCPServer(('127.0.0.1', 0), PythonConsoleServer)
  dbg("debugserver: listening on %s" % str(tcpserver.server_address))
  debugserver = threading.Thread(target=tcpserver.serve_forever, name="DebugServer")
  debugserver.setDaemon(True)
  debugserver.start()
  return(debugserver, tcpserver) 
开发者ID:OWASP,项目名称:NINJA-PingU,代码行数:10,代码来源:debugserver.py

示例15: serve

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import TCPServer [as 别名]
def serve():
    """Serve site at http://localhost:8000/"""
    os.chdir(env.deploy_path)

    class AddressReuseTCPServer(SocketServer.TCPServer):
        allow_reuse_address = True

    server = AddressReuseTCPServer(('', PORT), ComplexHTTPRequestHandler)

    sys.stderr.write('Serving on port {0} ...\n'.format(PORT))
    server.serve_forever() 
开发者ID:fullstackpython,项目名称:blog-code-examples,代码行数:13,代码来源:fabfile.py


注:本文中的SocketServer.TCPServer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。