blockchain , sdchain cpp sdk and demo
Dependencies: EthernetInterface mbed-rtos mbed uniqueCPUID
Fork of bcsdk by
Diff: Client.cpp
- Revision:
- 14:59412fcf8fa2
- Parent:
- 12:1b24ea479a59
- Child:
- 15:7ec76c840343
--- a/Client.cpp Thu May 17 13:36:46 2018 +0000 +++ b/Client.cpp Wed May 23 02:40:40 2018 +0000 @@ -7,7 +7,10 @@ Client::Client() { - m_strIP = "114.225.164.176"; + m_strIP = "49.76.122.41"; + string strDomain = "hengwell.asuscomm.com"; + getipbydomain(strDomain); + //m_strIP = strDomain; m_sPort = 26990; m_url = "/info"; m_host = "rest-beta.sdchain.io"; @@ -157,6 +160,7 @@ int Client::http_post_raw(const string &strIn,string &strOut) { + cout<<"Client::http_post_raw"<<endl; string strReq; string strRep; strReq = strIn; @@ -199,6 +203,7 @@ return SOCKET_ERROR; } */ + cout<<"ready to connect to server"<<endl; while (sClient.connect(m_strIP.c_str(), m_sPort) < 0) { printf("Unable to connect to (%s) on port (%d)\n", m_strIP.c_str(), m_sPort); wait(1); @@ -225,6 +230,7 @@ ret = sClient.send_all((char *)strReq.c_str(), strReq.length()); if (ret < 0) { + cout<<"send message error"<<endl; //get last error //get errno return ret; @@ -283,6 +289,7 @@ bool Client::build_get_raw(const string & url, const string & host, const string & token, const string & content, string & get_raw) { + cout<<"Client::build_get_raw"<<endl; bool ret = true; get_raw = ""; @@ -301,6 +308,7 @@ int Client::http_get(const string & url, const string & content, string & strOut) { + cout<<"Client::http_get"<<endl; string get_raw = ""; build_get_raw(url, content, get_raw); return http_post_raw(get_raw, strOut); @@ -309,4 +317,16 @@ int Client::http_get_raw(const string &strIn, string &strOut) { return http_post_raw(strIn, strOut); +} + +bool Client::getipbydomain(string& strDomain) +{ + string strIp; + struct hostent *host = gethostbyname(strDomain.c_str()); + for (int i = 0; host->h_addr_list[i]; i++){ + strDomain = (string)inet_ntoa(*(struct in_addr*)host->h_addr_list[i]); + break; + } + return true; + } \ No newline at end of file