PDA

View Full Version : Problem with tcp - client receive message



gelman
25th August 2011, 13:34
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):


QByteArray buffer;
buffer.clear();
buffer = socket->readAll();

if(buffer.size() == 0) //
{
qDebug("Error: Empty buffer.");
}

p1l->setText(buffer);

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.

yeye_olive
25th August 2011, 14:01
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?

gelman
25th August 2011, 14:59
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:



void SimpleChatClient::func()
{
socket->write("something");

QByteArray buffer;
buffer.clear();
socket->waitForReadyRead(5000);
buffer = socket->readAll();

if(buffer.size() == 0)
{
qDebug("Error: Empty buffer.");
}

p1l->setText(buffer);

}




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).

yeye_olive
25th August 2011, 15:35
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.