Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection can't be build #423

Open
wendy23oat opened this issue Mar 29, 2024 · 0 comments
Open

connection can't be build #423

wendy23oat opened this issue Mar 29, 2024 · 0 comments

Comments

@wendy23oat
Copy link

wendy23oat commented Mar 29, 2024

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant