Exemplo n.º 1
0
void* MyThread_run(void* thread_args)
{
	struct MyThread_args *args;
	args = (struct MyThread_args *)thread_args;
	CHttpClient hc;
	string res;
	int ret;
	ret = hc.Get("http://172.31.222.94:9000/?operation=query&username=root&password=123456&db_name=dbpedia&format=json&sparql="+args->sparql,res);
	int m = 0;
	for(int i = 0; i<args->sparql.length(); ++i)
	{
		if(args->sparql[i]=='?')
			++m;
		if(args->sparql[i]=='{')
			break;
	}
	int n = 0;
	for(int i = 0; i<res.length(); ++i)
	{
		if(res[i]=='{')
			++n;
	}
	int Num = (n-3)/(m+1);
	//if(Num<=10)
	//{
	//	ofstream f("result/"+int2string(args->num)+".txt");
	//	f<<res<<endl;
	//	f.close();
	//}	
	
	if(args->rnum != Num)
		correctness = false;
	pthread_exit(NULL);
}
Exemplo n.º 2
0
void CClient::connect()
{
    CHttpClient httpClient;
    string strUrl = m_strLoginDomain + "/msg_server";
    string strResp;
    CURLcode nRet = httpClient.Get(strUrl, strResp);
    if(nRet != CURLE_OK)
    {
        printf("login falied. access url:%s error\n", strUrl.c_str());
		g_configReturn = false;
        PROMPTION;
        return;
    }
    Json::Reader reader(Json::Features::strictMode());
    Json::Value value;
    if(!reader.parse(strResp, value))
    {
        printf("login falied. parse response error:%s\n", strResp.c_str());
		g_configReturn = false;
        PROMPTION;
        return;
    }
    string strPriorIp, strBackupIp;
    uint16_t nPort;
    try {
        uint32_t nRet = value["code"].asUInt();
        if(nRet != 0)
        {
            string strMsg = value["msg"].asString();
            printf("login falied. errorMsg:%s\n", strMsg.c_str());
			g_configReturn = false;
            PROMPTION;
            return;
        }
        strPriorIp = value["priorIP"].asString();
        strBackupIp = value["backupIP"].asString();
        nPort = string2int(value["port"].asString());
        
    } catch (std::runtime_error msg) {
        printf("login falied. get json error:%s\n", strResp.c_str());
		g_configReturn = false;
        PROMPTION;
        return;
    }

    g_pConn = new ClientConn(this);
    m_nHandle = g_pConn->connect(strBackupIp.c_str(), nPort, m_strName, m_strPass);
    if(m_nHandle != INVALID_SOCKET)
    {
        netlib_register_timer(CClient::TimerCallback, (void*)this, 1000);	
		g_configReturn = true;
    }
    else
    {
        printf("invalid socket handle\n");
    }
}
Exemplo n.º 3
0
// before you run this example, make sure that you have started up ghttp service (using bin/ghttp db_name port)
int main()
{

	CHttpClient hc;
	string res;
	int ret;

	//ret = hc.Get("http://172.31.222.94:9000/?operation=build&db_name=lubm&ds_path=data/LUBM_10.n3", res); 
	//cout<<res<<endl;
	
	//ret = hc.Get("http://172.31.222.94:9000/?operation=load&db_name=lubm", res); 
	//cout<<res<<endl;
	int result[6] = {10, 14, 14, 199424, 33910, 1039};
        string* sparql = new string[6];
        sparql[0] = "select ?v0 where\
                   {\
                   ?v0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/LanguagesOfBotswana> .\
                   ?v0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>    <http://dbpedia.org/class/yago/LanguagesOfNamibia> .\
                   ?v0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Language> .\
                   }";
        sparql[1] = "select ?v0 where\
                   {\
                   ?v0 <http://dbpedia.org/ontology/associatedBand> <http://dbpedia.org/resource/LCD_Soundsystem> .\
                   }";
        sparql[2] = "select ?v2 where\
                   {\
                   <http://dbpedia.org/resource/!!Destroy-Oh-Boy!!> <http://dbpedia.org/property/title> ?v2 .\
                   }";
        sparql[3] = "select ?v0 ?v2 where\
                   {\
                   ?v0 <http://dbpedia.org/ontology/activeYearsStartYear> ?v2 .\
                   }";
        sparql[4] = "select ?v0 ?v1 ?v2 where\
                   {\
                   ?v0 <http://dbpedia.org/property/dateOfBirth> ?v2 .\
                   ?v1 <http://dbpedia.org/property/genre> ?v2 .\
                   }";
        sparql[5] = "select ?v0 ?v1 ?v2 ?v3 where\
                   {\
                   ?v0 <http://dbpedia.org/property/familycolor> ?v1 .\
                   ?v0 <http://dbpedia.org/property/glotto> ?v2 .\
                   ?v0 <http://dbpedia.org/property/lc> ?v3 .\
                   }";
	int tnum = 6;
	tnum = 3000;
	bool correctness = true;
	for(int i = 0; i < tnum; ++i)
	{
		ret = hc.Get("http://172.31.222.94:9000/?operation=query&format=json&sparql="+sparql[i%6],res);
		cout<< i <<endl;
                int m = 0;
		for(int ii = 0; ii<sparql[i%6].length(); ++ii)
		{
			if(sparql[i%6][ii] == '?')
				++m;
			if(sparql[i%6][ii] == '{')
				break;
		}
		int n = 0;
		for(int ii = 0; ii<res.length(); ++ii)	
		{
			if(res[ii] == '{')
				++n;
		}
		int Num = (n-3)/(m+1);
		if(Num!=result[i%6])
			correctness =false;
		
	}
	if (correctness == true)
		cout<< "The answers are correct!" <<endl;
	else
		cout<< "The answers exist errors!" <<endl;
	//ret = hc.Get("127.0.0.1:8080/query/data/ex0.sql", res); 
	//cout<<res<<endl;
	
	//ret = hc.Get("http://172.31.222.94:9000/?operation=monitor", res); 
	//cout<<res<<endl;
	
	//ret = hc.Get("http://172.31.222.94:9000/?operation=unload&db_name=lubm", res); 
	//cout<<res<<endl;

	return 0;
}