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

Not able to close WebsocketClient If the connection is failed #1426

Open
tumusudheer opened this issue May 22, 2020 · 0 comments
Open

Not able to close WebsocketClient If the connection is failed #1426

tumusudheer opened this issue May 22, 2020 · 0 comments

Comments

@tumusudheer
Copy link

@tumusudheer tumusudheer commented May 22, 2020

Hi,

My sample Code:

socket_client = websocket_client();
try
    {
        socket_client.connect(Url_Address).wait();
    }
    catch(const websocket_exception& e)
    {
        std::cout << "error while connecting to the websocket server: "<< e.what() << "\n";
        return FAILURE;
    }
    catch (std::exception& e)
    {
        std::cout <<  "...... error while connecting to the websocket server: "<< e.what() << '\n';
        return FAILURE;
    }
    return SUCCESS;

And Close method

try
    {
        printf("Closing websocket connection  \n");fflush(stdout);
        socket_client.close().wait();
       printf("websocket Closed successfully  \n");fflush(stdout);
    }
    catch(const websocket_exception& e)
    {
        std::cout << "error while closing web socket"<< e.what() << "\n";
        return FAILURE;
    }
    return SUCCESS;

If I try the code with Url_Address=""; The connect method is going into the catch block and then returning the failure.
But when I'm trying to close the web socket,
I expected that the websocket close will be failed with some message and will be going in the catch block of close method.

But the line socket_client.close().wait(); is blocking forever and not exiting the code. I believe it is because of wait().

Is there something I can do like wait(5); // wait for 5 or n milli seconds ? and then exit.
When I try to pass wait(5), I'm getting error: no matching function for call to ?pplx::task<void>::wait(int)?

Also tried with unsigned int and getting the following error: no matching function for call to ?pplx::task<void>::wait(unsigned int&)?

What best suggestion I can in this scenario, as we are supposed to handle socket failure as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.