I am developing an MFC dialog application in VS2019 c++. Application requires multiple android devices to be connected as client to a windows application server through USB. Connecting multiple devices one by one at the starting of the windows application is working fine. But once an device is disconnected from USB, and reconnected again, the server is not accepting the client.
I tried using a thread detach() only to accept() clients in background.
UINT CCheckDlg::bindAndListen(LPVOID Param)
{
while (true)
{
ClientSocket = accept(ListenSocket, NULL, NULL);
}
return 0;
}
But this loop breaks out after 2 iterations, and while this loop runs, other UI operations of the Application are blocked also.
For the android client side, as soon as the android application catches socketExceptions, it tries to reconnect to server. When the USB is connected again, the try continues.
How can i have a thread in windows application which is runs in background accepting clients, without blocking the UI operations?