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

Calls to websocket_client::receive always return even if there is no incoming message #261

Open
generationtech opened this issue Oct 8, 2016 · 0 comments

Comments

@generationtech
Copy link

generationtech commented Oct 8, 2016

I bet there's an easy explanation for this or suggested implementation. I have (what I think) is a working websocket setup between cpprestsdk and django channel application across the network. I can send and receive test websocket messages between them.

On the cpprestsdk part, when I make calls to websocket_client::receive, it always returns even if there's no incoming message. How should I structure a program to block waiting for a new message or is there some other better way to handle this.

For now, I'm just using the sample code and calling it from a simple loop to verify this behavior.

void cl_WebsockManager::receive(void) { wsm_client.receive().then([](websocket_incoming_message msg) { return msg.extract_string(); }).then([](std::string body) { std::cout << body << std::endl; }); }

for (int i = 1; i < 100; i++) { std::cout << i << std::endl; wsm_game->receive(); }

I can't seem to find any detailed useful examples for the cpprestsdk implementation of websockets and the one community example referenced on the wiki seems really complicated for my purpose and if I understand that code, just runs basically a continuous recursive loop calling the .receive()
https://blogs.msdn.microsoft.com/vcblog/2014/06/25/c-rest-sdk-websocket-client/

Thanks for any help.

@generationtech generationtech changed the title Calls to web::websockets::client::websocket_client::receive always returns even if there is no data Calls to websocket_client::receive always returns even if there is no data Oct 8, 2016
@generationtech generationtech changed the title Calls to websocket_client::receive always returns even if there is no data Calls to websocket_client::receive always return even if there is no incoming message Oct 8, 2016
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