Results 1 to 12 of 12

Thread: readyRead problem

  1. #1
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default readyRead problem

    I've a problem with my client/server application...the strange behaviour is the following:
    1. Connect client-server
    2. Client send a message (msg#1) to server (time To) (this kind of message is sended to server every 5 seconds).
    2. Server receive msg#1 istantly (To+a bit latency delay) and send to client a new message (msg#2) just after msg# is received (time T1).
    2. Normally client must receive the msg#2 istantly T1 instead it receive msg#2 after 5 seconds, after client send the second time the msg#1.

    It seem that something is locking the readyRaed signal and only when I send the second time the msg#1 it's unlocked.

    Any idea about this problem?

    You can find the source code in this 3D:
    http://www.qtcentre.org/forum/f-qt-p...ate-22885.html

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: readyRead problem

    Do you have the event loop running in the thread where you handle the connection?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: readyRead problem

    Quote Originally Posted by wysota View Post
    Do you have the event loop running in the thread where you handle the connection?
    yes...infact I intercept other signal of my TcpRadio, except the readyRead signal or better...I intercept it with a delay of exactly 5 sec. respect what I want.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: readyRead problem

    Do you use any waitFor...() methods?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: readyRead problem

    Quote Originally Posted by wysota View Post
    Do you use any waitFor...() methods?
    yes...when I send a message:
    Qt Code:
    1. bool TcpConnection::sendMessage(const RadioMessageInterface* msg)
    2. {
    3. QByteArray block;
    4. QDataStream out(&block, QIODevice::WriteOnly);
    5.  
    6. int msgSize = 0;
    7. const char* data = msg->getData(msgSize);
    8.  
    9. out<<(quint16)msgSize;
    10. out.writeRawData(data,msgSize);
    11. out.device()->seek(0);
    12. out << quint16(block.size() - sizeof(quint16));
    13. int size = _socket->write(block);
    14.  
    15.  
    16. if(size != block.size())
    17. {
    18. return false;
    19. }
    20.  
    21. if(!_socket->waitForBytesWritten(_timeout))
    22. return false;
    23.  
    24. return true;
    25. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by fruzzo; 25th August 2009 at 18:49.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: readyRead problem

    Quote Originally Posted by fruzzo View Post
    yes...
    Why? There is no point in doing that if you have an event loop running...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: readyRead problem

    Quote Originally Posted by wysota View Post
    Why? There is no point in doing that if you have an event loop running...
    mhmmm...strange because if I remove the waitForBytesWritten no messagegs are sended on the socket

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: readyRead problem

    Then you have no event loop running in your thread. Where do you call QThread::exec()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: readyRead problem

    Quote Originally Posted by wysota View Post
    Then you have no event loop running in your thread. Where do you call QThread::exec()?
    This is the handler thread of the tcp radio:

    Qt Code:
    1. //**********************************************************************************************************************************************
    2. //Class TcpRadio Handler
    3. //**********************************************************************************************************************************************
    4.  
    5. TcpRadioHandler::TcpRadioHandler(RADIO_MODE_TYPE mode, int localPort,const Node& remoteNode, RadioMessageInterfaceCreatorFunction messageCreator, int timeout, char * logDir)
    6. :QThread(0), _tcpRadio(0), _mode(mode), _localPort(localPort), _peerNode(remoteNode), _creator(messageCreator), _timeout(timeout)
    7. {
    8. strcpy_s(_logDir, logDir);
    9. start();
    10. }
    11.  
    12. TcpRadioHandler::~TcpRadioHandler()
    13. {
    14. wait();
    15. if (_tcpRadio)
    16. delete _tcpRadio;
    17. }
    18.  
    19. TcpRadio * TcpRadioHandler::radio()
    20. {
    21. return _tcpRadio;
    22. }
    23.  
    24. void TcpRadioHandler::run()
    25. {
    26. _tcpRadio = new TcpRadio(_mode, _localPort, _peerNode, _creator, _timeout, _logDir);
    27. exec();
    28. }
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: readyRead problem

    Where and how do you create the socket you use in TcpConnection::sendMessage?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: readyRead problem

    Quote Originally Posted by wysota View Post
    Where and how do you create the socket you use in TcpConnection::sendMessage?
    Qt Code:
    1. void TcpRadio::connectToPeer()
    2. {
    3. if (_mode == SERVER)
    4. return;
    5. _peerNode.setConnection(TcpConnection::openOutcomingConnection(_peerNode.address(), _peerNode.port(), _creator, _timeout));
    6. const TcpConnection * conn = _peerNode.getConnection();
    7. connect(conn, SIGNAL(status(QString)), this, SIGNAL(updateStatus(QString)));
    8. connect(conn, SIGNAL(status(QString)), this, SLOT(writeLog(QString)));
    9. connect(conn, SIGNAL(readyRead()), this, SLOT(receive()));
    10. emit updateStatus("Opening connection with peer: " + _peerNode.address());
    11. }
    12.  
    13. TcpConnection* TcpConnection::openOutcomingConnection(const QString& serverName, int port, RadioMessageInterfaceCreatorFunction messageCreator, int timeout)
    14. {
    15. QTcpSocket* socket = new QTcpSocket();
    16. socket->connectToHost(serverName, port, QIODevice::ReadWrite);
    17. return new TcpConnection(socket, messageCreator, timeout);
    18. }
    To copy to clipboard, switch view to plain text mode 

    Howere I've solved the problem...without using signal/slots mecanism!

    Now I've another problem with disconnection...when I try to use disconnectFromHost from server, It don't disconnect (socket state is still connected) and the socket return a "Network time out" error. Than the Client crash on waitReadyRead.
    I try to insert a waitForDisconnected() just after the call of disconnectFromHost but without results: waitForDisconnected return always false ( waiting 30000 msecs too).

    Why?
    Last edited by fruzzo; 2nd September 2009 at 18:45.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: readyRead problem

    You should really make up your mind if you want to use the event queue or not.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 19
    Last Post: 3rd April 2009, 23:17
  2. Very strange socket programming problem
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2008, 12:05
  3. deployment problem: msvc++ 2008 Express, Qt 4.4.3
    By vonCZ in forum Qt Programming
    Replies: 7
    Last Post: 10th November 2008, 14:38
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  5. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.