I'm working on a project that uses uses a thread to connect to a server. Whenever the login button is pressed, it initialized a thread to log in with the given IP and port provided by the user.
ServerPage.h
class ServerPage {
public:
static std::thread serverThread;
static void login();
}
ServerPage.cpp
#include "ServerPage.h"
std::thread ServerPage::serverThread;
void ServerPage::login() {
while (/*server is not connected*/) {
if (/*button is clicked and thread is not running*/)
serverThread = std::thread(Client::init, ip, port);
}
}
This works well until the button is clicked more than once. I'm able to use the Client class to see the status of the server (connected, not connected, or failure) Is there a way to delete or re initialize so that it can be run until the client is connected?