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

How to use websocket to send messages actively? #413

Open
xwq112132 opened this issue Feb 10, 2023 · 1 comment
Open

How to use websocket to send messages actively? #413

xwq112132 opened this issue Feb 10, 2023 · 1 comment

Comments

@xwq112132
Copy link

xwq112132 commented Feb 10, 2023

I learned example_ws.cpp is an example. In this example, a server is built using the websocket protocol, and then listens for three types of messages: onopen, onclose, and onmessage. But like http1.1, this is also half-duplex. After the client connects with me, how can I actively send messages to the client as a server?

And the second half of the code of example_ws.cpp makes me wonder that commenting them does not affect websocket to listen to the above three types of messages. Can someone help me explain the role of the second half of the code?

This is the second half of the code of example_ws.cpp that puzzles me:

    CROW_ROUTE(app, "/")
    ([]{
        char name[256];
        gethostname(name, 256);
        crow::mustache::context x;
        x["servername"] = name;
	
        auto page = crow::mustache::load("ws.html");
        return page.render(x);
     });
@xwq112132
Copy link
Author

@thedrow @vadz @kumagi @xenosoz

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