@nagabathula
The TCP protocol allows the bidirectional transmission of streams of bytes. Each endpoint cannot guess in advance when the stream it receives will end. That is why there is a notion of connection: while the connection is open, each endpoint is prepared to receive additional data. It is only by closing the connection that one endpoint notifies the other that the communication is over.@marcvanriet-- I din't exactly understand how you always keep the client connection open.
By contrast, the UDP protocol is used for one-shot communication. A single block of data is transmitted in a single direction. There is no notion of connection here: the receiving end is simply notified that a block of data has arrived; the communication is already over.
The fortune example keeps things simple by using TCP for one-shot communication only. The server sends a fortune and immediately closes the connection.
In general you only close the TCP connection when the communication is definitely over. You can leave it open even if there is no data to transmit immediately.
Using QTCPSocket, call disconnectFromHost() (or delete the object) to close the connection. Use the disconnected() signal to be notified when the connection is closed by the other endpoint.




Reply With Quote
Bookmarks