示例#1
0
def get_protocol(service_name):
    transport = TSocket.TSocket('127.0.0.1', 9999)
    transport = TTransport.TBufferedTransport(transport)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    defined_protocol = TMultiplexedProtocol(protocol, service_name)
    transport.open()  #打开链接
    time.sleep(0.5)
    if transport.isOpen():
        connect_handler = ConnectServiceNoneHandler()
        conn_processor = ConnectService.Processor(connect_handler)
        if conn_processor.process(protocol, protocol):
            return defined_protocol
    return None
示例#2
0
def cmd_server_process():
    try:
        transport = TSocket.TSocket('127.0.0.1', 9999)
        transport = TTransport.TBufferedTransport(transport)
        protocol = TBinaryProtocol.TBinaryProtocol(transport)
        mul_protocol = TMultiplexedProtocol(protocol, "ConnectService")
        connect_handler = ConnectServiceHandler(mul_protocol)
        conn_processor = ConnectService.Processor(connect_handler)
        transport.open()  #打开链接
        #startThreadService(cmd_client_process, mul_protocol, cmdstr="TestCmd")
        while True:
            conn_processor.process(protocol, protocol)
    except TTransport.TTransportException as tx:
        print("cmd_server_process Error TTransport.TTransportException == {}".
              format(tx))
    except Exception as x:
        print("Error Exeption == {}".format(x))
示例#3
0
            if msq_type:
                connect_handler.client_connected(protocol)
            else:
                connect_handler.client_closed(protocol)
        except Exception as x:
            print("Error Exeption == {}".format(x))


mng_handler = ManageServiceHandler()
mng_processor = ManageService.Processor(mng_handler)

file_handler = FileServiceHandler()
file_processor = FileService.Processor(file_handler)

connect_handler = ConnectServiceHandler()
conn_processor = ConnectService.Processor(connect_handler)

tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()

processor = TMultiplexedProcessor()  #使用TMultiplexedProcessor接收多个处理
processor.registerProcessor("ManageService", mng_processor)
processor.registerProcessor("FileService", file_processor)
processor.registerProcessor("ConnectService", conn_processor)

transport = TSocket.TServerSocket('0.0.0.0', 9999)
#server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
server = TServer.TThreadPoolServer(processor, transport, tfactory, pfactory)
server.setNumThreads(6000)  # 1个主线程 1个监听线程 + 多少个通信线程
# start client connect handler: save client socket info
conn_mq_thread = threading.Thread(target=thrift_connect_handler,