def _create_client(self, host, port, send_timeout=None, recv_timeout=None, framed_transport=False): """ @param host: hostname / ip address @type host: str @param port: @type port: int @param send_timeout: milliseconds @type send_timeout: int @param recv_timeout: milliseconds @type recv_timeout: int @param framed_transport: @type framed_transport: bool @return: @rtype: Rest.Client """ socket = thrift.transport.TSocket.TSocket(host, port) if send_timeout is not None: socket.setSendTimeout(send_timeout) if recv_timeout is not None: socket.setRecvTimeout(recv_timeout) if framed_transport: transport = thrift.transport.TTransport.TFramedTransport(socket) else: transport = thrift.transport.TTransport.TBufferedTransport(socket) protocol = thrift.protocol.TBinaryProtocol.TBinaryProtocolAccelerated(transport) client = Rest.Client(protocol) transport.open() return client
def new_client(host=None, port=None): cfg = mapserv.config.load() host = host if host is not None else cfg['iface'] port = port if port is not None else cfg['port'] socket = TSocket.TSocket(host, port) transport = TTransport.TBufferedTransport(socket) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = QueryService.Client(protocol) transport.open() return client
def connect_to_atbr_thrift_service(hostname, portnum): try: transport = TSocket.TSocket(hostname, portnum) transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) atbr_thrift_service = atbrthrift.AtbrStorage.Client(protocol) transport.open() return atbr_thrift_service except Exception, e: logging.error(e) traceback.print_exc()
def create_client_open_connection(self, transport, protocol, service): """creates the client and open the connection to the server Arguments: transport {thrift.transport} -- the transport object protocol {thrift.protocol} -- the protocol object service {thrift.client} -- the interface client """ # Create the client client = service.Client(protocol) # Connect transport.open() return client