Skip to content

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

Open
@generationtech

Description

@generationtech

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions