[Interest] ThreadedFortune example extending to send message forever

Viktor Engelmann viktor.engelmann at qt.io
Mon Sep 5 16:38:09 CEST 2016


so you got the server running :-)

what was the problem?


Maybe it hangs inside waitForDisconnected? Have you tried waiting for
more than 30 seconds (the default timeout of the method)?

Do you hard-code the client side port number? the same
client-IP/client-Port/server-IP/server-Port combination cannot be used
again within 2 minutes after a disconnect - the operating system
suppresses that. That is to prevent late packets from the old connection
to be falsely passed to the new connection. After 2 minutes, such
packets must have timed out and be dropped, so the same combination can
be reused safely.

Regards

Viktor


Am 03.09.2016 um 18:13 schrieb Nilesh Kokane:
> Hello,
>
> I extended Threaded fortune to send message in infinite loop as below,
> but then it only send once and I get the socket error. I've not
> changed the fortune client but I only press Get fortune once and
> expect the message to be sent continuously which isn't a case.
>
> Is it really needed to abort() the tcpSocket from the client side and
> connectToHost per message? Doing so I get the incomingConnection and
> removing the forever loop of the below function it works as expected?
>
>
>
> void FortuneThread::run()
> {
>
>    forever
>     {
>         QTcpSocket tcpSocket;
>         QString temp_text =  text.at(qrand() % text.size());
>         qDebug() << "text from thread" << temp_text;
>         if (!tcpSocket.setSocketDescriptor(socketDescriptor)) {
>             emit error(tcpSocket.error());
>             qDebug() <<  "socket error";
>             return;
>         }
>         QByteArray block;
>         QDataStream out(&block, QIODevice::WriteOnly);
>         out.setVersion(QDataStream::Qt_4_0);
>         out << temp_text;
>         //! [3] //! [4]
>
>         tcpSocket.write(block);
>         tcpSocket.disconnectFromHost();
>         tcpSocket.waitForDisconnected();
>
>     }
>  }
> }
>
>
> Any clue?
>

-- 


Viktor Engelmann
Software Engineer

The Qt Company GmbH
Rudower Chaussee 13
D-12489 Berlin
Viktor.Engelmann at qt.io
+49 151 26784521
http://qt.io

Geschäftsführer: Mika Pälsi, Juha Varelius, Mika Harjuaho
Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht
Charlottenburg, HRB 144331 B
<http://qt.io>
<http://www.facebook.com/Qt> 	<http://www.twitter.com/qtproject>
<https://www.linkedin.com/company/the-qt-company/>
<https://plus.google.com/104580575722059274792>
<https://www.youtube.com/QtStudios>

Qt World Summit 2016 <http://qtworldsummit.com/>
Qt World Summit 2016 | Pier 27, San Francisco, CA
Experience Exponential Potential on October 18-20
www.qtworldsummit.com <http://www.qtworldsummit.com>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160905/cce07542/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_logo_with_text_green_rgb_400x141.png
Type: image/png
Size: 16849 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160905/cce07542/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_facebook.png
Type: image/png
Size: 1407 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160905/cce07542/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_twitter.png
Type: image/png
Size: 1778 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160905/cce07542/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_linkedin.png
Type: image/png
Size: 1532 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160905/cce07542/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_googleplus.png
Type: image/png
Size: 1957 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160905/cce07542/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_youtube.png
Type: image/png
Size: 1610 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160905/cce07542/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qtworldsummit2016_banner.jpg
Type: image/jpeg
Size: 35183 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160905/cce07542/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: viktor_engelmann.vcf
Type: text/x-vcard
Size: 271 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160905/cce07542/attachment.vcf>


More information about the Interest mailing list