hi everybody
ı am prepairing a client programme which takes data from server.how can ı take data from server.
Printable View
hi everybody
ı am prepairing a client programme which takes data from server.how can ı take data from server.
Which kind of server do you have?
Hi again,
I am writing a socket programme and i send data to my server.
Code:
bool TcpClient::connectToServer() { if(!isConnectionOpen()) { tcpSocket->connectToHost(_serverAddress,_serverPort); } return true; } { if(!isConnectionOpen()) { connectToServer(); } tcpSocket->write((sendMsg+"\n").toAscii().data()); return "OK"; }
This function is return OK. I want to return response from server. For example;
My send data : Hello
Server Response : blablabla
this function's response : blablabla
How can I return response from server. I use TCP-IP protocol.
the better solution is use the signal/slot mechanism connecting the QAbstractSocket::readyRead() signal with one custom slot.
If you want use a single method that sends and receives data you must use code like:
Code:
tcpSocket->write((sendMsg+"\n").toAscii().data()); bool ready = false; while (!ready) { // Wait for data received ready = tcpSocket->waitForReadyRead(); // Check if you can read a line \n terminated ready &= tcpSocket->canReadLine(); } return result;