samedi 30 janvier 2021

How to send data via a websocket using uWebsockets v0.14?

You can send data after connecting like:

 hubGroup->onConnection([](uWS::WebSocket<uWS::CLIENT> *ws, uWS::HttpRequest req) {
    std::cout << "connect, sending HELLO" << std::endl;
    std::string msg = "HELLO";
    ws->send(msg.data(), msg.size(), uWS::OpCode::TEXT);
});

How can I do ws->send() out of the event loop? That is, how can I send data without hubGroup->on*() methods?

Aucun commentaire:

Enregistrer un commentaire