Answer the question
In order to leave comments, you need to log in
How to handle websocket in qml?
Hello !!! I am writing a simple chat on QT, more precisely on qml, just wondering. It is clear that the server is starting and let's say from the js script on the HTML page the client i.e. websockets work and the server sends messages back to the socket, but how to process in qml (and is it possible) several sockets on the server, let's say general mailing or chat, I can't understand the documentation has a websocket description, but I just don't know what to do with the code the simplest
WebSocketServer {
port: 1234
id: server
listen: true
onClientConnected: {
webSocket.onTextMessageReceived.connect(function(message) {
appendMessage(qsTr("Server received message: %1").arg(message));
webSocket.sendTextMessage(qsTr("Hello Client!"));
});
}
onErrorStringChanged: {
appendMessage(qsTr("Server error: %1").arg(errorString));
}
}
here's how to find out the right socket in processing i.e. if not back to the request to send to this client and to another socket?
Answer the question
In order to leave comments, you need to log in
When the onClientConnected signal fires, you have a webSocket object - it can be used for some associative container that will store all connected client sockets. To initialize such a container, it is better to handle the clientConnected signal first.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question