| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 2 | |
Hello, I am trying to write a client/threaded server app using QTcpSocket. After about 30 sec, my client gets dissconnected, any idea why? In the thread's run() I do : tcpSocket->waitForDisconnected(); tcpSocket->disconnectFromHost(); QTextStream out(stdout); out << "Client disconnected!" << endl; The rest is implemented using signals/slots. Also, if my client dies I get a Segmentation fault on the server, what needs to be done when a client dies to prevent this? Thank you very much, Gabriel -- [ signature omitted ]
On Sunday 05 November 2006 12:55, Gabriel Rossetti wrote: > I am trying to write a client/threaded server app using QTcpSocket. > After about 30 sec, my client gets dissconnected, any idea why? > In the thread's run() I do : > > tcpSocket->waitForDisconnected(); > tcpSocket->disconnectFromHost(); You should exchange these two lines. Give the socket the command to disconnect first and then wait for it to complete the command. You are seeing 30s because that is the default timeout of the wait* functions. > QTextStream out(stdout); > out << "Client disconnected!" << endl; > > The rest is implemented using signals/slots. > > Also, if my client dies I get a Segmentation fault on the server, what > needs to be done when a client dies to prevent this? For this socket call deleteLater() instead of delete'ing it directly - TCP sockets need to do some cleaning up after close() or shutdown() has been called, so you should schedule the deletion after the closing. Konrad
Attachment:
Attachment:
pgpv0pd3ut34f.pgp
Description: PGP signature