本文整理汇总了Python中SocketServer.ThreadingTCPServer.serve_forever方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadingTCPServer.serve_forever方法的具体用法?Python ThreadingTCPServer.serve_forever怎么用?Python ThreadingTCPServer.serve_forever使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketServer.ThreadingTCPServer
的用法示例。
在下文中一共展示了ThreadingTCPServer.serve_forever方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from SocketServer import ThreadingTCPServer [as 别名]
# 或者: from SocketServer.ThreadingTCPServer import serve_forever [as 别名]
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()
示例2: ConnServer
# 需要导入模块: from SocketServer import ThreadingTCPServer [as 别名]
# 或者: from SocketServer.ThreadingTCPServer import serve_forever [as 别名]
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;
示例3: start
# 需要导入模块: from SocketServer import ThreadingTCPServer [as 别名]
# 或者: from SocketServer.ThreadingTCPServer import serve_forever [as 别名]
def start(program, options):
ThreadingTCPServer.allow_reuse_address = True
server = ThreadingTCPServer((host, port), QuasselGrepHandler)
server.program = program
server.options = options
server.serve_forever()
print "Finishing."
示例4: main
# 需要导入模块: from SocketServer import ThreadingTCPServer [as 别名]
# 或者: from SocketServer.ThreadingTCPServer import serve_forever [as 别名]
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()
示例5: run_as_backup_offline
# 需要导入模块: from SocketServer import ThreadingTCPServer [as 别名]
# 或者: from SocketServer.ThreadingTCPServer import serve_forever [as 别名]
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())
示例6: start
# 需要导入模块: from SocketServer import ThreadingTCPServer [as 别名]
# 或者: from SocketServer.ThreadingTCPServer import serve_forever [as 别名]
def start(port=21567):
"""
this function to start the server, and maintain listening the port.
"""
host = ''
address = (host, port)
tcpServ = ThreadingTCPServer(address, MyRequestHandler)
print 'waiting for connection...'
tcpServ.serve_forever()
示例7: serve_forever
# 需要导入模块: from SocketServer import ThreadingTCPServer [as 别名]
# 或者: from SocketServer.ThreadingTCPServer import serve_forever [as 别名]
def serve_forever(self):
try:
ThreadingTCPServer.serve_forever(self)
except Exception, e:
if not self.run:
return
raise
示例8: _server
# 需要导入模块: from SocketServer import ThreadingTCPServer [as 别名]
# 或者: from SocketServer.ThreadingTCPServer import serve_forever [as 别名]
def _server(self):
"""
进程服务入口函数
"""
host= ''
ADDR = (host, self.port)
TCP.allow_reuse_address = True
tcpServ = TCP(ADDR, MyRequestHandler)
print 'waiting for connection...'
tcpServ.serve_forever()
示例9: Server
# 需要导入模块: from SocketServer import ThreadingTCPServer [as 别名]
# 或者: from SocketServer.ThreadingTCPServer import serve_forever [as 别名]
class Server(Thread):
def __init__(self, host="127.0.0.1", port=3794, handler=Handler):
Thread.__init__(self)
self.server = ThreadingTCPServer((host, port), handler)
def run(self):
self.server.serve_forever()
def stopRunning(self):
self.server.shutdown()
self.server.server_close()
示例10: start_server
# 需要导入模块: from SocketServer import ThreadingTCPServer [as 别名]
# 或者: from SocketServer.ThreadingTCPServer import serve_forever [as 别名]
def start_server(host, port):
try:
addr = (host, port)
server = ThreadingTCPServer(addr, client_handler)
print_log("waitting connect...")
print_log("Listen {}:{}".format("localhost", port))
server.serve_forever()
except Exception as e:
print_log("threading tcp server error {}".format(e))
示例11: main
# 需要导入模块: from SocketServer import ThreadingTCPServer [as 别名]
# 或者: from SocketServer.ThreadingTCPServer import serve_forever [as 别名]
def main():
global world
world = World()
z = ThreadingTCPServer(('', 4000), MudHandler)
try: z.serve_forever()
except KeyboardInterrupt:
world.global_message('World is shutting down')
for plr in world.players_at_location(None):
try: plr.parse('quit')
except: print 'ERROR: %s could not quit gracefully' % plr.name
z.server_close()
world.save()
示例12: LogServer
# 需要导入模块: from SocketServer import ThreadingTCPServer [as 别名]
# 或者: from SocketServer.ThreadingTCPServer import serve_forever [as 别名]
class LogServer():
'''由于serve_forever()是阻塞的,所以需要单开一个进程或线程来开启日志服务'''
def __init__(self, addr, requestHandler):
self.bindAddress = addr
self.requestHandler = requestHandler
logging.config.fileConfig(LOGCONFIG)
def start(self):
self.svr = ThreadingTCPServer(self.bindAddress, self.requestHandler)
self.svr.serve_forever()
def stop(self):
self.svr.shutdown()
示例13: createAndStartServer
# 需要导入模块: from SocketServer import ThreadingTCPServer [as 别名]
# 或者: from SocketServer.ThreadingTCPServer import serve_forever [as 别名]
def createAndStartServer():
global serv
ThreadingTCPServer.allow_reuse_address = True
serv = ThreadingTCPServer(('', 20000), SocketHandler,
bind_and_activate=False)
l_onoff = 1
l_linger = 0
serv.socket.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
struct.pack('ii', l_onoff, l_linger))
serv.server_bind()
serv.server_activate()
HP.logger.info('Starting server')
serv.serve_forever() # blocking method
示例14: start_tcp_server
# 需要导入模块: from SocketServer import ThreadingTCPServer [as 别名]
# 或者: from SocketServer.ThreadingTCPServer import serve_forever [as 别名]
def start_tcp_server():
class Handler(BaseRequestHandler):
def handle (self):
addr = self.request.getpeername()
log.info('Got a connection from {0}'.format(str(addr)))
while True:
data = self.request.recv(socketclient.SOCKET_BUFFER_SIZE).strip()
if not data:break
log.info('receive from ({0}):\n{1}'.format(self.client_address, data))
data_dict = ndb.load_string(data)
taskinfo = data_dict.get('root')
if taskinfo == None:
self.request.send('task command error'.encode('utf8'))
return
task_type = taskinfo.get('tasktype')
_type = taskinfo.get('type')
task_id = taskinfo.get('taskid')
send_data = {'error':'error'}
if task_type =='collect' and _type == 'rules':
data_dict['datas'] = config_cache.load_rules()
send_data = ndb.build_node('root', data_dict)
elif task_type =='collect' and _type == 'agent':
data_dict['datas'] = controller.load_agent_config()
send_data = ndb.build_node('root', data_dict)
elif task_type =='collect' and _type == 'status':
data_dict['datas'] = collect.collect().load_status()
elif task_type =='collect' and _type == 'sysinfo':
data_dict['datas'] = config_cache.load_sysinfo()
elif task_type =='control' and _type == 'rule':
datas = taskinfo.get('datas')
data_dict['datas'] = task_manage.execute_job(task_id, datas)
elif task_type =='control' and _type == 'preview':
datas = taskinfo.get('datas')
data_dict['datas'] = task_manage.preview_job(datas)
send_data = ndb.build_node('root', data_dict)
self.request.send(send_data.encode('utf8'))
#获取本地IP
local_ip = controller.load_agent_config().get('host', '127.0.0.1')
#获取配置文件中的服务端口
service_port = int(controller.load_agent_config().get('tcp_server_port', 8888))
print 'start server' + str(local_ip) + ':' + str(service_port)
server = ThreadingTCPServer((local_ip, service_port), Handler)
server.serve_forever()
示例15: run
# 需要导入模块: from SocketServer import ThreadingTCPServer [as 别名]
# 或者: from SocketServer.ThreadingTCPServer import serve_forever [as 别名]
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)
PORT = 50001
srv = ThreadingTCPServer((HOST,PORT), XMLRequestHandler)
self.socket = srv.socket
srv.serve_forever()