QTcpSocket.. send data from server :(?
-
Hey,
I've been trying to develop a client-server application using Qt (testing on localhost..), but I cannot solve this problem:
I've stored the sockets returned by nextPendingConnection of the server and I have to sometimes send messages from the server to clients, but WITHOUT the client making a request first. However, this does not seem to work.. if I use the write() method on the saved socket, the Client's readyRead() signal won't fire. Could someone help me figure out why, please?
-
@PhantomR Is the client still connected if you try to send something to it?
"WITHOUT the client making a request first" - how should this work? The client needs to connect to the server first, so it has to send a request first. -
I think it should, since I doubt I manually closed the connection and the client program was not stopped. I tried displaying the results of isWritable, isOpen, isReadable, isValid (methods of the socket),.. they all returned true. The client does connect to start with and he also make requests. However, from time to time I want the server to send some notifications to the client without him requesting that (I'm trying to build some kind of forum and when a topic is modified by some user, the Server will notify subscribers to that topic (other clients).. this is why I need the server to be able to send messages to clients without a request from them).
Thank you for your reply :).
-
@PhantomR Did you take a look at examples like http://doc.qt.io/qt-5/qtnetwork-fortuneserver-example.html ?
-
Thank you for your help :) I didn't really look at them.. maybe I should. Still, something seemed to work after I changed the writing method from using QTextStream to just using the socket's write() [actually, I may have tried both methods.. I'm not that sure why it works now] ? Not sure why though.. is it possible that using QTextStream closes the Socket after a write/flush?