Skip to content

Please help me check the issues with the client #1772

@lingshaomao

Description

@lingshaomao

I want to implement a client:

`#include <uwebsockets/App.h>
#include
#include

using namespace std;

class UserData
{
};

int main() {
string url = "ws://localhost:9001";

uWS::App app;
uWS::App::WebSocketBehavior<UserData> behavior;
//auto behavior = uWS::App::WebSocketBehavior<UserData>();

behavior.open = [](uWS::WebSocket<false, true, UserData>* ws, uWS::HttpRequest req) {
	std::cout << "Connected to the server!" << std::endl;
	ws->send("Hello from the client!");
};

behavior.message = [](uWS::WebSocket<false, true, UserData>* ws, std::string_view message, uWS::OpCode opCode) {
	std::cout << "Received message: " << message << std::endl;
};

behavior.close = [](uWS::WebSocket<false, true, UserData>* ws, int code, std::string_view message) {
	std::cout << "Disconnected from the server!" << std::endl;
};

behavior.ping = [](uWS::WebSocket<false, true, UserData>* ws, std::string_view message) {
	std::cout << "Received ping: " << message << std::endl;
};

behavior.pong = [](uWS::WebSocket<false, true, UserData>* ws, std::string_view message) {
	std::cout << "Received pong: " << message << std::endl;
};

//app.ws<UserData>(url, std::forward<decltype(behavior)>(behavior));
app.ws<UserData>(url, std::move(behavior));
//app.ws<UserData>(url, behavior);

app.run();

return 0;

}`

But this code reported an error in VS2022 with C++20:
error C2440: “”: cannot convert from “initializer list” to “ofats::any_invocable<void (uWS::WebSocket<false,true,UserData> *)>”

Help me please

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