本文整理汇总了Python中SocketServer.ThreadingTCPServer方法的典型用法代码示例。如果您正苦于以下问题:Python SocketServer.ThreadingTCPServer方法的具体用法?Python SocketServer.ThreadingTCPServer怎么用?Python SocketServer.ThreadingTCPServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketServer
的用法示例。
在下文中一共展示了SocketServer.ThreadingTCPServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingTCPServer [as 别名]
def __init__(self, addr = ('localhost', 8000),
RequestHandler = SOAPRequestHandler, log = 0, encoding = 'UTF-8',
config = Config, namespace = None, ssl_context = None):
# Test the encoding, raising an exception if it's not known
if encoding != None:
''.encode(encoding)
if ssl_context != None and not config.SSLserver:
raise AttributeError, \
"SSL server not supported by this Python installation"
self.namespace = namespace
self.objmap = {}
self.funcmap = {}
self.ssl_context = ssl_context
self.encoding = encoding
self.config = config
self.log = log
self.allow_reuse_address= 1
SocketServer.ThreadingTCPServer.__init__(self, addr, RequestHandler)
# only define class if Unix domain sockets are available
示例2: run
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingTCPServer [as 别名]
def run(self, ip='0.0.0.0', port=3240):
#SocketServer.TCPServer.allow_reuse_address = True
self.server = SocketServer.ThreadingTCPServer((ip, port), USBIPConnection)
self.server.usbcontainer = self
self.server.serve_forever()
示例3: __init__
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingTCPServer [as 别名]
def __init__(self):
super(server, self).__init__()
self.srv = SocketServer.ThreadingTCPServer((CTCore.HOST, CTCore.PORT), TCPHandler)
示例4: __init__
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingTCPServer [as 别名]
def __init__(self, remote_server, ssh_transport, *args, **kwargs):
self.remote_server = remote_server
self.ssh_transport = ssh_transport
socketserver.ThreadingTCPServer.__init__(self, *args, **kwargs)
示例5: test_ThreadingTCPServer
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingTCPServer [as 别名]
def test_ThreadingTCPServer(self):
self.run_server(SocketServer.ThreadingTCPServer,
SocketServer.StreamRequestHandler,
self.stream_examine)
示例6: handle_error
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingTCPServer [as 别名]
def handle_error(self, *args):
"""make ThreadingTCPServer happy"""
etype, value = sys.exc_info()[:2]
if isinstance(value, NetWorkIOError) and 'bad write retry' in value.args[1]:
etype = value = None
else:
del etype, value
SocketServer.ThreadingTCPServer.handle_error(self, *args)
示例7: main
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingTCPServer [as 别名]
def main():
import argparse
global trace_file, TARGET_HOST, TARGET_PORT
HOST, PORT = "localhost", 8090
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--trace_file', type=argparse.FileType('w'))
parser.add_argument('-b', '--bind', default=HOST)
parser.add_argument('-p', '--port', type=int, default=PORT)
parser.add_argument('-n', '--negotiate', help='Negotiate with the given server name')
parser.add_argument('TARGET_HOST')
parser.add_argument('TARGET_PORT', type=int)
args = parser.parse_args()
TARGET_HOST = args.TARGET_HOST
TARGET_PORT = args.TARGET_PORT
trace_file = args.trace_file
register_types()
NETTCPProxy.negotiate = bool(args.negotiate)
NETTCPProxy.server_name = args.negotiate
if GSSAPIStream is None and NETTCPProxy.negotiate:
log.error("GSSAPI not available, negotiation not possible. Try python2 with gssapi")
sys.exit(1)
server = SocketServer.ThreadingTCPServer((args.bind, args.port), NETTCPProxy)
server.serve_forever()
示例8: start_server
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingTCPServer [as 别名]
def start_server(debugflag=False):
try:
server = socketserver.ThreadingTCPServer(("", 50000), ServerSocket)
server.conn = debugflag
print "[DAEMON] Hellman Server Started"
server.serve_forever()
except:
pass
示例9: __init__
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingTCPServer [as 别名]
def __init__(self, host='localhost',
port=None,
handler=LogRecordStreamHandler):
if port is None:
port = logging.handlers.DEFAULT_TCP_LOGGING_PORT
SocketServer.ThreadingTCPServer.__init__(self, (host, port), handler)
示例10: __init__
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingTCPServer [as 别名]
def __init__(self, port=8000):
self._server_address = ("127.0.0.1", port)
self._handler = SimpleHTTPRequestHandlerHere
self.httpd = ThreadingTCPServer(
self._server_address, self._handler, bind_and_activate=False
)
示例11: __init__
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingTCPServer [as 别名]
def __init__(self, *args, **kwargs):
self.cfg = Config()
self.analysistasks = {}
self.analysishandlers = {}
ip = self.cfg.resultserver.ip
self.port = int(self.cfg.resultserver.port)
while True:
try:
server_addr = ip, self.port
SocketServer.ThreadingTCPServer.__init__(self,
server_addr,
ResultHandler,
*args,
**kwargs)
except Exception as e:
# In Linux /usr/include/asm-generic/errno-base.h.
# EADDRINUSE 98 (Address already in use)
# In Mac OS X or FreeBSD:
# EADDRINUSE 48 (Address already in use)
if e.errno == 98 or e.errno == 48:
log.warning("Cannot bind ResultServer on port {0}, "
"trying another port.".format(self.port))
self.port += 1
else:
raise CuckooCriticalError("Unable to bind ResultServer on "
"{0}:{1}: {2}".format(
ip, self.port, str(e)))
else:
log.debug("ResultServer running on {0}:{1}.".format(ip, self.port))
self.servethread = Thread(target=self.serve_forever)
self.servethread.setDaemon(True)
self.servethread.start()
break
示例12: start_server
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingTCPServer [as 别名]
def start_server(cls):
"""starting the server to listen"""
if cls.inst().__server is None:
try:
socketserver.ThreadingTCPServer.allow_reuse_address = True
address = (Options.get_ip(), Options.get_port_sourcetrail_to_vim())
cls.inst().__server = socketserver.ThreadingTCPServer(address, ConnectionHandler)
server_thread = threading.Thread(target=cls.inst().__server.serve_forever)
server_thread.daemon = True
server_thread.start()
except socket.error:
print("Socket needed for Sourcetrail plugin already in use")
示例13: __init__
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingTCPServer [as 别名]
def __init__(self, listener, RequestHandlerClass, bind_and_activate=True):
"""Constructor. May be extended, do not override."""
if hasattr(listener, 'getsockname'):
SocketServer.BaseServer.__init__(self, listener.getsockname(), RequestHandlerClass)
self.socket = listener
else:
SocketServer.ThreadingTCPServer.__init__(self, listener, RequestHandlerClass, bind_and_activate)
示例14: handle_error
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingTCPServer [as 别名]
def handle_error(self, *args):
"""make ThreadingTCPServer happy"""
exc_info = sys.exc_info()
error = exc_info and len(exc_info) and exc_info[1]
if isinstance(error, (socket.error, ssl.SSLError, OpenSSL.SSL.Error)) and len(error.args) > 1 and 'bad write retry' in error.args[1]:
exc_info = error = None
else:
del exc_info, error
SocketServer.ThreadingTCPServer.handle_error(self, *args)
示例15: __init__
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingTCPServer [as 别名]
def __init__(self, host=DEFAULT_HOST, port=DEFAULT_PORT, handler=LogHandler):
"""Initialize the log receiver
:param host: The hostname to bind to
:param port: The port to listen on
:param handler: The handler to send received messages to
"""
socketserver.ThreadingTCPServer.__init__(self, (host, port), handler)
self.abort = 0
self.timeout = 1
self.logname = None