The server doesn't print any messages to the console after client connection

Hello,

Why my server example prints only Listening at the port: 3000. But it doesn’t print two words: connected and hoge after the client connection. My client send a word hoge to the server that should print it in the server/app.js here:

wss.on("connection", client => {

    console.log("connected");
    client.send(makeMessage(serverEvents.outgoing.HELLO, JSON.stringify({ message: "hello from server" })));

    client.onmessage =
        (event) =>
        {
            console.log(event.data);
        }
});

But the client receives the hello from server message from the server:

onopen
onmessage
message: {"action":"scGravity","data":"{\"message\":\"hello from server\"}"}

It works on Render without problems: https://connect-with-server-opengles20-sdl3-wasm.onrender.com/

image

Hi there - are you looking under “Logs” in the Glitch editor (it’s among the tools on the bottom of the page)? That’s where your server logs would show if they’re printing out.

You can see a simple server code in my online example above here: server/app.js:

wss.on("connection", client => {

    console.log("connected");
    client.send(makeMessage(serverEvents.outgoing.HELLO, JSON.stringify({ message: "hello from server" })));

    client.onmessage =
        (event) =>
        {
            console.log(event.data);
        }
});

The server side should prints two words in the console: connected and hoge after the client connection but the server doesn’t print these messages to the Logs window:

Where does the client connection happen in this code - or is it in another app?

The client connection happen in server/app.js:

wss.on("connection", client => {

    console.log("connected");
    client.send(makeMessage(serverEvents.outgoing.HELLO, JSON.stringify({ message: "hello from server" })));

When it happen the server send to the client the hello from server message. If you run my example from the first post and open the browser console you can see that the client takes a message from the server and prints it:

Please, open my example from the first post, run the client:

image

Open the browser console and open the Logs.

I uses SDL3 for the client that is built to WebAssembly. It is a code for connection on the client side and sending the hoge word to the server (that the server should print to the Logs window):

#include <emscripten.h>
#include <emscripten/html5.h>
#include <emscripten/websocket.h>

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

    EMSCRIPTEN_RESULT result;
    result = emscripten_websocket_send_utf8_text(websocketEvent->socket, "hoge");
    if (result)
    {
        std::cout << "Failed to emscripten_websocket_send_utf8_text(): " << result << std::endl;
    }

    return EM_TRUE;
}


int SDL_AppInit(void **appstate, int argc, char *argv[])
{
    // ...

    EmscriptenWebSocketCreateAttributes ws_attrs = {
        //"ws:://localhost:3000",
        //"wss://connect-with-server-opengles20-sdl3-wasm.onrender.com",
        "wss://testing-websockets-using-emscripten-sdl3-and-opengl-es-20.glitch.me",
        NULL,
        EM_TRUE
    };

    EMSCRIPTEN_WEBSOCKET_T ws = emscripten_websocket_new(&ws_attrs);
    emscripten_websocket_set_onopen_callback(ws, NULL, onopen);
    emscripten_websocket_set_onerror_callback(ws, NULL, onerror);
    emscripten_websocket_set_onclose_callback(ws, NULL, onclose);
    emscripten_websocket_set_onmessage_callback(ws, NULL, onmessage);

    // ...

I don’t think that it is a problem with my example or Emscripten because I have deployed the same example on the Render hosting and it prints two words after the client connection:

image