First app with WebSockets

118 views
Skip to first unread message

Ivan Enzhaev

unread,
Jul 6, 2024, 8:39:36 PM7/6/24
to emscripten-discuss
Hello,

I try to run the shorter version this example: https://gist.github.com/nus/564e9e57e4c107faa1a45b8332c265b9

I compile with this command:  emcc -lwebsocket.js -g src/client/main.cpp -o public/main.html
It compiles without problems: 

```
emcc -lwebsocket.js -g src/client/main.cpp -o public/main.html cache:INFO: generating system asset: symbol_lists/f1b6fbba91d4f7c17e21f323c8df509adb00db34.json... (this will be cached in "C:\emsdk\upstream\emscripten\cache\symbol_lists\f1b6fbba91d4f7c17e21f323c8df509adb00db34.json" for subsequent builds)
```

```cpp
#include <emscripten/websocket.h>

#include <iostream>

EM_BOOL onopen(int eventType, const EmscriptenWebSocketOpenEvent *websocketEvent, void *userData) {
    std::cout << "onopen" << std::endl;
    return EM_TRUE;
}

int main()
{
    EmscriptenWebSocketCreateAttributes ws_attrs = {
        "wss://localhost:3000",
        NULL,
        EM_TRUE
    };

    EMSCRIPTEN_WEBSOCKET_T ws = emscripten_websocket_new(&ws_attrs);
    emscripten_websocket_set_onopen_callback(ws, NULL, onopen);
    return 0;
}
```

But I have the error in the browser:

```
```

Ivan Enzhaev

unread,
Jul 6, 2024, 9:38:00 PM7/6/24
to emscripte...@googlegroups.com

ebsocket.js to CMakeLists.txt. I try this: SET(EMSCRIPTEN_LINK_FLAGS "-lwebsocket.js") But it didn't help


--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/_gTgnzwnWWU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/212285fa-314f-4ac5-9e55-248132892f86n%40googlegroups.com.

Ivan Enzhaev

unread,
Jul 6, 2024, 10:20:23 PM7/6/24
to emscripte...@googlegroups.com
I have solved it!
```cmake
if(CMAKE_SYSTEM_NAME MATCHES Emscripten)
    set(CMAKE_EXECUTABLE_SUFFIX ".html" CACHE INTERNAL "")

    #SET(EMSCRIPTEN_LINK_FLAGS "-lwebsocket.js")
    target_link_options("${EXECUTABLE_NAME}" PRIVATE "-lwebsocket.js")
```

Ivan Enzhaev

unread,
Jul 6, 2024, 10:20:43 PM7/6/24
to emscripte...@googlegroups.com
I have solved it!
```cmake
if(CMAKE_SYSTEM_NAME MATCHES Emscripten)
    set(CMAKE_EXECUTABLE_SUFFIX ".html" CACHE INTERNAL "")

    target_link_options("${EXECUTABLE_NAME}" PRIVATE "-lwebsocket.js")
```

Sam Clegg

unread,
Jul 8, 2024, 12:33:27 AM7/8/24
to emscripte...@googlegroups.com
Regarding the missing malloc export, I uploaded a fix here: https://github.com/emscripten-core/emscripten/pull/22198

cheers,
sam

You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAPxskvHb-qJg0aoQEWvgS82wSkxwFWpBJw_fxu9YN0AkkR%2BNcA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages