Python SocketServer.ThreadingTCPServer() Examples

The following are 20 code examples of SocketServer.ThreadingTCPServer(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module SocketServer , or try the search function .
Example #1
Source File: Server.py    From p2pool-n with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #2
Source File: server.py    From pyxform with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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
        ) 
Example #3
Source File: test_socketserver.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_ThreadingTCPServer(self):
        self.run_server(SocketServer.ThreadingTCPServer,
                        SocketServer.StreamRequestHandler,
                        self.stream_examine) 
Example #4
Source File: receivers.py    From multilog with MIT License 5 votes vote down vote up
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 
Example #5
Source File: proxylib.py    From arkc-client with GNU General Public License v2.0 5 votes vote down vote up
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) 
Example #6
Source File: proxylib.py    From arkc-client with GNU General Public License v2.0 5 votes vote down vote up
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) 
Example #7
Source File: test_socketserver.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_ThreadingTCPServer(self):
        self.run_server(SocketServer.ThreadingTCPServer,
                        SocketServer.StreamRequestHandler,
                        self.stream_examine) 
Example #8
Source File: sourcetrail.py    From vim-sourcetrail with MIT License 5 votes vote down vote up
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") 
Example #9
Source File: test_socketserver.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_ThreadingTCPServer(self):
        self.run_server(SocketServer.ThreadingTCPServer,
                        SocketServer.StreamRequestHandler,
                        self.stream_examine) 
Example #10
Source File: resultserver.py    From CuckooSploit with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #11
Source File: USBIP.py    From PythonUSBIP with The Unlicense 5 votes vote down vote up
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() 
Example #12
Source File: LoggingWebMonitor.py    From HPOlib with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #13
Source File: DH.py    From networking with GNU General Public License v3.0 5 votes vote down vote up
def start_server(debugflag=False):
	try:
		server = socketserver.ThreadingTCPServer(("", 50000), ServerSocket)
		server.conn = debugflag
		print "[DAEMON] Hellman Server Started"
		server.serve_forever()
	except:
		pass 
Example #14
Source File: proxy.py    From net.tcp-proxy with GNU General Public License v3.0 5 votes vote down vote up
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() 
Example #15
Source File: test_socketserver.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_ThreadingTCPServer(self):
        self.run_server(SocketServer.ThreadingTCPServer,
                        SocketServer.StreamRequestHandler,
                        self.stream_examine) 
Example #16
Source File: web_control.py    From oss-ftp with MIT License 5 votes vote down vote up
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) 
Example #17
Source File: test_socketserver.py    From BinderFilter with MIT License 5 votes vote down vote up
def test_ThreadingTCPServer(self):
        self.run_server(SocketServer.ThreadingTCPServer,
                        SocketServer.StreamRequestHandler,
                        self.stream_examine) 
Example #18
Source File: test_socketserver.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_ThreadingTCPServer(self):
        self.run_server(SocketServer.ThreadingTCPServer,
                        SocketServer.StreamRequestHandler,
                        self.stream_examine) 
Example #19
Source File: ssh_forward.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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) 
Example #20
Source File: CTServer.py    From CapTipper with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        super(server, self).__init__()
        self.srv = SocketServer.ThreadingTCPServer((CTCore.HOST, CTCore.PORT), TCPHandler)