Results 1 to 4 of 4

Thread: Problem with tcp - client receive message

  1. #1
    Join Date
    Aug 2011
    Posts
    2
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Problem with tcp - client receive message

    Hi, I'm making simple application in qt form my mobile phone (symbian), but I have problem with receiving message from server (computer) to client (mobile), which I want to set as text in label.
    I dont know qt very well but I can make sending msg from client to server.

    I did this (dont work):

    Qt Code:
    1. QByteArray buffer;
    2. buffer.clear();
    3. buffer = socket->readAll();
    4.  
    5. if(buffer.size() == 0) //
    6. {
    7. qDebug("Error: Empty buffer.");
    8. }
    9.  
    10. p1l->setText(buffer);
    To copy to clipboard, switch view to plain text mode 

    I'm getting error all the time and I dont know what to do. I tried do this in many ways and I googled a lot but with no result.
    I would appreciate all your help.

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 96 Times in 93 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with tcp - client receive message

    I'm getting error all the time
    What error? Do you mean your debug message? If yes, then it is because there was no data to read in the socket. Use the readyRead() slot to know when to read.
    I googled a lot but with no result
    What did you Google for?

    Have you checked out Qt's networking examples?

  3. #3
    Join Date
    Aug 2011
    Posts
    2
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: Problem with tcp - client receive message

    What error? Do you mean your debug message?
    Yes.

    Have you checked out Qt's networking examples?
    A lot of them, and they dont work for me.



    After my app starts i press "connect" button and server recognize my client perfectly. Next, I'm pressing another button and I'm calling this function:

    Qt Code:
    1. void SimpleChatClient::func()
    2. {
    3. socket->write("something");
    4.  
    5. QByteArray buffer;
    6. buffer.clear();
    7. socket->waitForReadyRead(5000);
    8. buffer = socket->readAll();
    9.  
    10. if(buffer.size() == 0)
    11. {
    12. qDebug("Error: Empty buffer.");
    13. }
    14.  
    15. p1l->setText(buffer);
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 




    which is sending message to server. Server receive this msg and is sending msg to client, and now problem starts - I cant receive this msg from server (I think server is ok, becouse client made in python works good).

  4. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 96 Times in 93 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with tcp - client receive message

    What does
    socket->waitForReadyRead(5000)
    return? If it returns false, then it is because of a timeout or an error. Try increasing the timeout value and check the socket error state.

    A lot of them, and they dont work for me.
    Why? What you are trying to achieve is slightly more complex than the Fortune client.

    Also, I would recommend using the non-blocking API of QTcpSocket.

Similar Threads

  1. udp receive data problem
    By zxwmail in forum Newbie
    Replies: 9
    Last Post: 21st June 2011, 23:11
  2. Server don't receive a new request of client
    By tchoninho in forum Qt Programming
    Replies: 4
    Last Post: 27th May 2011, 09:50
  3. receive data from client via QTcpServer
    By Fallen_ in forum Qt Programming
    Replies: 4
    Last Post: 8th September 2010, 17:08
  4. Replies: 4
    Last Post: 18th August 2010, 09:13
  5. How I can get the message from client
    By mraittin in forum Qt Programming
    Replies: 2
    Last Post: 7th September 2007, 14:41

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.