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

Problem with provided default example inside documentation #1785

Open
jakubhaumer opened this issue Sep 20, 2024 · 4 comments
Open

Problem with provided default example inside documentation #1785

jakubhaumer opened this issue Sep 20, 2024 · 4 comments

Comments

@jakubhaumer
Copy link

jakubhaumer commented Sep 20, 2024

I pulled out the provided example inside the uWebSockets documentation which goes:

`#include <App.h>
#include <utility>
#include <iostream>

struct UserData {
    // Define any data you want to associate with each WebSocket connection
};

int main() {
    uWS::App().ws<UserData>("/*", uWS::WebSocketBehavior<UserData>{
        /* Settings */
        .compression = uWS::SHARED_COMPRESSOR,
        .maxPayloadLength = 16 * 1024,
        .idleTimeout = 10,
        /* Handlers */
        .upgrade = [](auto *res, auto *req, auto *context) {
            // Handle upgrade request
        },
        .open = [](auto *ws) {
            // Handle connection opened
        },
        .message = [](auto *ws, std::string_view message, uWS::OpCode opCode) {
            ws->send(message, opCode);
        },
        .drain = [](auto *ws) {
            // Handle drain event
        },
        .ping = [](auto *ws) {
            // Handle ping event
        },
        .pong = [](auto *ws) {
            // Handle pong event
        },
        .close = [](auto *ws, int code, std::string_view message) {
            // Handle connection closed
        }
    }).run();
}
`

And im unable to compile that code. Im having problem with second argument inside the .ws() method. I cannot do rvalue nor lvalue. Using std::move() is not working, initializing right inside the method does not work too. Explicit usage of the type does not work too. Here is my cmake --build . --verbose:

`Change Dir: '/Users/me/documents/Programming/test/multiprocessing/realtime_build'

Run Build Command(s): /opt/homebrew/Cellar/cmake/3.30.3/bin/cmake -E env VERBOSE=1 /usr/bin/make -f Makefile
/opt/homebrew/Cellar/cmake/3.30.3/bin/cmake -S/Users/me/documents/Programming/test/multiprocessing/realtime_fetcher -B/Users/me/documents/Programming/test/multiprocessing/realtime_build --check-build-system CMakeFiles/Makefile.cmake 0
/opt/homebrew/Cellar/cmake/3.30.3/bin/cmake -E cmake_progress_start /Users/me/documents/Programming/test/multiprocessing/realtime_build/CMakeFiles /Users/me/documents/Programming/test/multiprocessing/realtime_build//CMakeFiles/progress.marks
/Library/Developer/CommandLineTools/usr/bin/make  -f CMakeFiles/Makefile2 all
/Library/Developer/CommandLineTools/usr/bin/make  -f CMakeFiles/realtime_fetcher.dir/build.make CMakeFiles/realtime_fetcher.dir/depend
cd /Users/me/documents/Programming/test/multiprocessing/realtime_build && /opt/homebrew/Cellar/cmake/3.30.3/bin/cmake -E cmake_depends "Unix Makefiles" /Users/me/documents/Programming/test/multiprocessing/realtime_fetcher /Users/me/documents/Programming/test/multiprocessing/realtime_fetcher /Users/me/documents/Programming/test/multiprocessing/realtime_build /Users/me/documents/Programming/test/multiprocessing/realtime_build /Users/me/documents/Programming/test/multiprocessing/realtime_build/CMakeFiles/realtime_fetcher.dir/DependInfo.cmake "--color="
Dependencies file "CMakeFiles/realtime_fetcher.dir/Users/me/documents/Programming/test/multiprocessing/src/realtime_fetcher.cpp.o.d" is newer than depends file "/Users/me/documents/Programming/test/multiprocessing/realtime_build/CMakeFiles/realtime_fetcher.dir/compiler_depend.internal".
Consolidate compiler generated dependencies of target realtime_fetcher
/Library/Developer/CommandLineTools/usr/bin/make  -f CMakeFiles/realtime_fetcher.dir/build.make CMakeFiles/realtime_fetcher.dir/build
[ 50%] Building CXX object CMakeFiles/realtime_fetcher.dir/Users/me/documents/Programming/test/multiprocessing/src/realtime_fetcher.cpp.o
/Library/Developer/CommandLineTools/usr/bin/c++  -I/Users/me/documents/Programming/test/multiprocessing/realtime_fetcher/../include -I/Users/me/documents/Programming/test/multiprocessing/realtime_fetcher/../include/openssl-3.3.2/include -I/Users/me/documents/Programming/test/multiprocessing/realtime_fetcher/../include/rapidjson-1.1.0/include -I/Users/me/documents/Programming/test/multiprocessing/realtime_fetcher/../include/uWebSockets/src -I/Users/me/documents/Programming/test/multiprocessing/realtime_fetcher/../include/uSockets -I/Users/me/documents/Programming/test/multiprocessing/realtime_fetcher/../include/zlib -I/Users/me/documents/Programming/test/multiprocessing/realtime_fetcher/../include/zlib/build -isystem /opt/homebrew/include -std=gnu++20 -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk -MD -MT CMakeFiles/realtime_fetcher.dir/Users/me/documents/Programming/test/multiprocessing/src/realtime_fetcher.cpp.o -MF CMakeFiles/realtime_fetcher.dir/Users/me/documents/Programming/test/multiprocessing/src/realtime_fetcher.cpp.o.d -o CMakeFiles/realtime_fetcher.dir/Users/me/documents/Programming/test/multiprocessing/src/realtime_fetcher.cpp.o -c /Users/me/documents/Programming/test/multiprocessing/src/realtime_fetcher.cpp
/Users/me/documents/Programming/test/multiprocessing/src/realtime_fetcher.cpp:82:14: error: no matching member function for call to 'ws'
  uWS::App().ws<UserData>("/*", {
  ~~~~~~~~~~~^~~~~~~~~~~~
/Users/me/documents/Programming/test/multiprocessing/realtime_fetcher/../include/uWebSockets/src/App.h:272:32: note: candidate function template not viable: cannot convert initializer list argument to 'WebSocketBehavior<UserData>'
    BuilderPatternReturnType &&ws(std::string pattern, WebSocketBehavior<UserData> &&behavior) {
                               ^
1 error generated.
make[2]: *** [CMakeFiles/realtime_fetcher.dir/Users/me/documents/Programming/test/multiprocessing/src/realtime_fetcher.cpp.o] Error 1
make[1]: *** [CMakeFiles/realtime_fetcher.dir/all] Error 2
make: *** [all] Error 2`
@uNetworkingAB
Copy link
Contributor

You compile the examples by hitting "make".

@Jacob-Burckhardt
Copy link

@uNetworkingAB ,

Please add std::string_view parameters to ping and pong in the documentation.

Thanks.

@jakubhaumer
Copy link
Author

You compile the examples by hitting "make".

But its not inside example, its inside my program.

@jakubhaumer
Copy link
Author

jakubhaumer commented Sep 22, 2024

The issue has been resolved using this:

#include <App.h>

struct UserData {

};

int main() {
   uWS::App().ws<UserData>("/*", {
    /* Settings */
    .compression = uWS::SHARED_COMPRESSOR,
    .maxPayloadLength = 16 * 1024,
    .idleTimeout = 10,
    /* Handlers */
    .upgrade = [](auto *res, auto *req, auto *context) {
        /* You may read from req only here, and COPY whatever you need into your PerSocketData.
         * See UpgradeSync and UpgradeAsync examples. */
    },
    .open = [](auto *ws) {

    },
    .message = [](auto *ws, std::string_view message, uWS::OpCode opCode) {
        ws->send(message, opCode);
    },
    .drain = [](auto *ws) {
        /* Check getBufferedAmount here */
    },
    .ping = [](auto *ws, std::string_view) {

    },
    .pong = [](auto *ws, std::string_view) {

    },
    .close = [](auto *ws, int code, std::string_view message) {

    }
    }).connect("ws://localhost:9001", nullptr).run();

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

3 participants