userver: samples/websocket_service/websocket_service.cpp
Loading...
Searching...
No Matches
samples/websocket_service/websocket_service.cpp
namespace samples::websocket {
class WebsocketsHandler final : public server::websocket::WebsocketHandlerBase {
public:
// `kName` is used as the component name in static config
static constexpr std::string_view kName = "websocket-handler";
// Component is valid after construction and is able to accept requests
using WebsocketHandlerBase::WebsocketHandlerBase;
chat.Recv(message); // throws on closed/dropped connection
if (message.close_status) break; // explicit close if any
chat.Send(std::move(message)); // throws on closed/dropped connection
}
if (message.close_status) chat.Close(*message.close_status);
}
};
} // namespace samples::websocket
int main(int argc, char* argv[]) {
const auto component_list =
components::MinimalServerComponentList().Append<samples::websocket::WebsocketsHandler>();
return utils::DaemonMain(argc, argv, component_list);
}