I wrote a simple server example in JavaScript that sends some data to a client when the client connects: send-gravity-from-server-to-client-box2d-wasm-js
I deployed this simple server on free hostings: https://glitch.com/ and https://render.com/. Web clients work well:
- Glitch: https://merciful-regal-soursop.glitch.me
- Render: https://send-gravity-box2d-wasm-js.onrender.com
(It takes 15-20 seconds for Glitch and 50 seconds for Render to wake up the server)
I try to connect to the server from Qt and show received data:
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
connect(&m_webSocket, &QWebSocket::connected, this, &Widget::onConnected);
connect(&m_webSocket, &QWebSocket::textMessageReceived,
this, &Widget::onMessageReceived);
// QUrl url("wss://send-gravity-box2d-wasm-js.onrender.com");
QUrl url("wss://merciful-regal-soursop.glitch.me");
m_webSocket.open(url);
}
Widget::~Widget() {}
void Widget::onConnected()
{
qDebug() << "connected";
}
void Widget::onMessageReceived(const QString &message)
{
qDebug() << message;
}
I see connected
in the Qt Debug console when I try to connect to Render and I see nothing when I try to connect to Glitch.