當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。