c++socketsnetwork-programmingwebsocketuwebsockets

no instance of function template "uWS::CachingApp<SSL>::ws [with SSL=false]" matches the argument list, uWebSockets


I've been trying for hours to make the uWebSockets library work but I have no clue now. When using this code:

#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) {

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

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

    }
    });
}

Im getting this error:

no instance of function template "uWS::CachingApp<SSL>::ws [with SSL=false]" matches the argument list

I'm even more confused because uWebSockets documentation provides similar example which after copying into code does exactly the same error. I have no clue why this is not working.

EDIT:

Full error using 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

Solution

  • Add std::string_view parameters to ping and pong like 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) {
    
        }
        });
    }