connection can't be build
wendy23oat opened this issue · 0 comments
wendy23oat commented
After I used cmake to compile the library on Linux, I created my c++ project. However, I did not use QT. Instead, I chose to write the cmakelist file myself and compile it. After the compilation was successful, I executed it, but could not successfully establish a connection with the backend. , and no error was reported.
cmake_minimum_required(VERSION 3.0)
project(YourProjectName)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(sioclient REQUIRED)
find_package(jsoncpp REQUIRED)
add_executable(main main.cpp test.cpp test1.cpp test2.cpp)
target_include_directories(main PRIVATE /usr/local/include /usr/include/jsoncpp)
target_link_libraries(main PRIVATE sioclient sioclient_tls pthread jsoncpp)
and i create a connection class
class Connection{
public:
explict Connection(std::map<std::string, std::string> query, const std::string url);
~ Connection();
void start();
private:
void OnConnected(std::string const& nsp);
void OnClosed(std::string const& nsp);
sio::client h;
sio::socket::ptr current_socket;
std::string serverUrl;
std::map<std::string, std::string> Query;
};
Connection(std::map<std::string, std::string> query, const std::string url)
: serverUrl(url), Query(query)
{
h.set_open_listener(std::bind(&Connection::OnConnected,this,std::placeholders::_1));
h.set_close_listener(std::bind(&Connection::OnClosed,this,std::placeholders::_1));
}
Connection::~Connection(){
stop();
}
void start(){
h.connect(serverUrl, Query);
current_socket = h.socket();
std::cout<<"test"<<std::endl;
}
my main.cpp is
int main(){
std::map<std::string, std::string> query;
std::string id = "1"
query["id"]=id;
std::string url="http://myaddress:myport/";
Connection *connection = new Connection(query,url);
connection->start();
return 0;
}