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


Python SocketServer.ThreadingTCPServer类代码示例

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


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

示例1: __init__

    def __init__(self, host="", port=COBRA_PORT, sslcrt=None, sslkey=None, sslca=None, msgpack=False, json=False):
        '''
        Construct a cobra daemon object.

        Parameters:
        host        - Optional hostname/ip to bind the service to (default: inaddr_any)
        port        - The port to bind (Default: COBRA_PORT)
        msgpack     - Use msgpack serialization

        # SSL Options
        sslcrt / sslkey     - Specify sslcrt and sslkey to enable SSL server side
        sslca               - Specify an SSL CA key to use validating client certs

        '''
        self.thr = None
        self.run = True
        self.shared = {}
        self.dowith = {}
        self.host = host
        self.port = port
        self.reflock = RLock()
        self.refcnts = {}
        self.authmod = None
        self.sflags = 0

        if msgpack and json:
            raise Exception('CobraDaemon can not use both msgpack *and* json!')

        if msgpack:
            requireMsgpack()
            self.sflags |= SFLAG_MSGPACK

        if json:
            self.sflags |= SFLAG_JSON

        # SSL Options
        self.sslca = sslca
        self.sslcrt = sslcrt
        self.sslkey = sslkey

        self.cansetattr = True
        self.cangetattr = True

        if sslcrt and not os.path.isfile(sslcrt):
            raise Exception('CobraDaemon: sslcrt param must be a file!')

        if sslkey and not os.path.isfile(sslkey):
            raise Exception('CobraDaemon: sslkey param must be a file!')

        if sslca and not os.path.isfile(sslca):
            raise Exception('CobraDaemon: sslca param must be a file!')

        self.allow_reuse_address = True
        ThreadingTCPServer.__init__(self, (host, port), CobraRequestHandler)

        if port == 0:
            self.port = self.socket.getsockname()[1]

        self.daemon_threads = True
        self.recvtimeout = None
开发者ID:BwRy,项目名称:vivisect,代码行数:60,代码来源:__init__.py

示例2: shutdown

 def shutdown(self):
     """Stop the server."""
     # this is the call for shutting down the server
     ThreadingTCPServer.shutdown(self)
     # wait until all the requests have finished
     for h in self.handlers.values():
         h.join()
开发者ID:Fiware,项目名称:i2nd.Robotics,代码行数:7,代码来源:rcmp_inter_communication.py

示例3: run

 def run(self): 
     """
 
     """
     s = None
     HOST = ''; # Symbolic name meaning the local host.
     if sys.platform.startswith("win"):
         HOST = socket.gethostbyaddr(socket.gethostname())[2][0]
     else:
         import commands
         temp = commands.getoutput('/sbin/ifconfig')
         HOST = re.search('inet addr:(\d+\.\d+\.\d+\.\d+)', temp).group(1)
     if USER_PORT:
         print "listening on port: %s" % xoom_server_port
         PORT = xoom_server_port
         print "================="
     else:
         print "XXXX not port specified, using default port: %s" % default_xoom_server_port
         PORT = default_xoom_server_port 
     print "PORT: %s" % PORT
     print "SERVER->HOST: %s, SERVER->PORT: %s" % (HOST, PORT) 
     srv = ThreadingTCPServer((HOST,int(PORT)), XMLRequestHandler)
     self.socket = srv.socket
     print "srv socket: %s" % self.socket
     srv.serve_forever()
开发者ID:pruan,项目名称:TestDepot,代码行数:25,代码来源:xoomServer.py

示例4: FileSearchServer

class FileSearchServer(Thread):
	""" Thread which answers to file/tag queries sent through unix socket. """
	def __init__(self, pname='SET_ME_PLEASE'):

		Thread.__init__(self)

		self.name = "%s/%s" % (
			pname, str(self.__class__).rsplit('.', 1)[1].split("'")[0])

		# old socket from a crashed daemon ?
		# remove it, the ThreadingUnixStreamServer will create it.
		#if os.path.exists(socket_path): os.unlink(socket_path)

		self._stop_event = Event()
		self.server     = ThreadingTCPServer(('127.0.0.1', searcher_port), FileSearchRequestHandler)
		self.server.allow_reuse_address = True

		# TODO: the socket is set to non-blocking to be able to gracefully terminate the thread,
		# but this could lead to CPU hogging problems. VERIFY THIS !!
		self.server.socket.setblocking(False)
	def run(self):
		logging.progress("%s: thread running." % (self.getName()))
		#os.chmod(socket_path, stat.S_IRUSR|stat.S_IWUSR|stat.S_IRGRP|stat.S_IWGRP|stat.S_IROTH|stat.S_IWOTH)
		while not self._stop_event.isSet():
			self.server.handle_request()
			time.sleep(0.01)
		logging.progress("%s: thread ended." % (self.getName()))
	def stop(self):
		if not self._stop_event.isSet():
			logging.progress("%s: stopping thread." % (self.getName()))
			self._stop_event.set()
			self.server.socket.close()
			self.server.server_close()
			if os.path.exists(socket_path):
				os.unlink(socket_path)
开发者ID:Licorn,项目名称:licorn,代码行数:35,代码来源:searcher.py

示例5: __init__

 def __init__(self, host='localhost', port=DEFAULT_LOGGING_CONFIG_PORT,
              handler=None):
     ThreadingTCPServer.__init__(self, (host, port), handler)
     logging._acquireLock()
     self.abort = 0
     logging._releaseLock()
     self.timeout = 1
开发者ID:CovenantEyes,项目名称:gunicorn,代码行数:7,代码来源:logging_config.py

示例6: __init__

 def __init__(self, address, handler):
     self._logger = logging.getLogger('GlobalTCPServer')
     self._logger.debug('__init__')
     self._command_set = { 0 : self.subscribe,
                           1 : self.unsubscribe,
                           8 : self.start_correlator,
                           9 : self.stop_correlator,
                           10 : self.get_integration_time,
                           11 : self.set_integration_time,
                           32 : self.get_phase_offsets,
                           33 : self.set_phase_offsets,
                           34 : self.get_delay_offsets,
                           35 : self.set_delay_offsets,
                           ##TODO
                           36 : self.get_algorithm,
                           37 : self.set_algorithm,
                           
                           255 : self.shutdown,
                          }
     self._started = False
     self._n_antennas = 8
     self._integration_time = 16 #sec
     
     self.antennas_remaping = {0:6, 1:1, 2:2, 3:3, 4:4, 5:5, 6:7, 7:8}
     
     self._correlator = None #TODO-2
     self._delay_control = SingleBlockmappingDelayControl({"/dev/ttyS4" : (6,1,2,3), "/dev/ttyS5" : (4,5,7,8)})
     
     self._stop_spread_event = Event()
             
     ThreadingTCPServer.__init__(self, address, handler)
开发者ID:sma-wideband,项目名称:phringes,代码行数:31,代码来源:server.py

示例7: __init__

 def __init__(self, host='localhost',
                          port=logging.handlers.DEFAULT_TCP_LOGGING_PORT,
                  handler=LogRecordStreamHandler):
     ThreadingTCPServer.__init__(self, (host, port), handler)
     self.abort = False
     self.timeout = 0.1
     self.finished = threading.Event()
开发者ID:CRYPTOlab,项目名称:python-resin,代码行数:7,代码来源:test_logging.py

示例8: __init__

 def __init__(
     self, host="localhost", port=logging.handlers.DEFAULT_TCP_LOGGING_PORT, handler=LogRecordStreamHandler
 ):
     ThreadingTCPServer.__init__(self, (host, port), handler)
     self.abort = 0
     self.timeout = 1
     self.logname = None
开发者ID:bebestmaple,项目名称:Hammer,代码行数:7,代码来源:logrecv.py

示例9: ConnServer

class ConnServer(Thread):
	def __init__(self):
		Thread.__init__(self)
		self.PORT = 1236
		self.init = False
		self.startrecv = False
		
		global g_p
		g_p = ConnProc()

		global g_connlist
		g_connlist = []
		global g_connid
		g_connid = []

	def run(self):
		self.initSock()

	def executeCommand(self, cmd):
		# not implemented yet
		#print 
		r = g_p.ProcCommand(cmd)
		print r

	def initSock(self):

		try:
			self.client = ThreadingTCPServer( ('', self.PORT), RecvServer)
			print 'listening on PORT', self.PORT
			self.client.serve_forever()
		except Exception, e:
			print e

		self.init = True;
开发者ID:kuna,项目名称:controller_server,代码行数:34,代码来源:serverTCP.py

示例10: __init__

 def __init__(self, port, deviceFd, deviceLock, debug = False, aexServer = None):
     '''
     Constructor
     '''
     self.running = False
     
     self.__dataQueue = Queue(0)
     
     self.__clients = []
     self.debug = debug
     
     self.__deviceFd = deviceFd
     self.deviceLock = deviceLock
     self.aexServer=aexServer
     
     self.runningTime = 0
     self.receivingTime = 0
     self.packetsReceived = 0
     self.sleepingTimes = 0
     
     ThreadingTCPServer.__init__(self, ("", port), StimNetCom, False)
     
     ThreadingTCPServer.allow_reuse_address = True
     
     self.server_bind()
     self.server_activate()
     
     Thread.__init__(self)
开发者ID:federicohyo,项目名称:mn256r1_ncs,代码行数:28,代码来源:StimServer.py

示例11: __init__

 def __init__(self, port, auth=False, user_manager=UserManager(), allowed=None):
     ThreadingTCPServer.__init__(self, ('', port), Socks5RequestHandler)
     self.__port = port
     self.__users = {}
     self.__auth = auth
     self.__user_manager = user_manager
     self.__sessions = {}
     self.allowed = allowed
开发者ID:fengyouchao,项目名称:pysocks,代码行数:8,代码来源:socks5.py

示例12: __init__

 def __init__(self, server_address, RequestHandlerClass, key, opts): 
     ThreadingTCPServer.__init__(self, server_address,
                                 RequestHandlerClass)
     self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,
                            1)
     self.key = key
     self.opts = opts
     self.initSecurity()
开发者ID:danieljohnlewis,项目名称:pisces,代码行数:8,代码来源:ttls_server.py

示例13: main

def main():
    level = logging.INFO
    logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s',
                        datefmt='%m/%d/%Y %I:%M:%S %p',
                        level=level)
    ThreadingTCPServer.allow_reuse_address = True
    server = ThreadingTCPServer(('0.0.0.0', 8118), Encoder)
    server.serve_forever()
开发者ID:wynemo,项目名称:kiss-proxy,代码行数:8,代码来源:pure-http.py

示例14: run_as_backup_offline

def run_as_backup_offline():
    logging.info("begin run as backup offline")
    global backup_ip
    global backup_port
    server_address = (backup_ip, backup_port)
    server = ThreadingTCPServer(server_address, MyStreamRequestHandler)
    server.serve_forever()
    logging.error(traceback.format_exc())
开发者ID:sdgdsffdsfff,项目名称:dshb,代码行数:8,代码来源:dshb.py

示例15: process_request_thread

 def process_request_thread(self, request, client_address):
     try:
         ThreadingTCPServer.process_request_thread(
             self, request, client_address)
     finally:
         # Client is no longer connected, remove the reference
         del self.clients[client_address]
         print 'self.clients', pformat(self.clients)
开发者ID:Web5design,项目名称:kuyruk,代码行数:8,代码来源:server.py


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