how can i send QStringList index by index
Hi
i want send data from client to server index by index.
but client packet all of index
i put client code and server result, and sorry for my weak english
Client Code:
QStringList ql={"1","2","3","4"};
foreach (QString tmp, ql) {
socket->write(tmp.toUtf8()+"\n");
socket->flush();
}
Server Result:
"1\n2\n3\n4\n"
Re: how can i send QStringList index by index
And what's the actual problem? The server received all the data or didn't it?
Re: how can i send QStringList index by index
recived all data but client send all of data to one packet!
I want client send QStringList One by One
Server code:
QStringList ql;
void ::MainWindow readyRead()
{
QString buff=QString(qobject_cast<QTcpSocket*>(sender())->readAll());
qDebug()<<buff;
ql.append(buff);
}
And want server result like this:
"1\n"
"2\n"
"3\n"
"4\n"
Re: how can i send QStringList index by index
tcp is stream-based... so I don't see what's wrong here.
Re: how can i send QStringList index by index
actually i have a text file.client must send line by line of file to server and server must process line by line of data but client packet many of line and then send to server.
as result server recive many of line and wrong process .
this is my problem i hope you understand .thanks to you
Re: how can i send QStringList index by index
Then split your received stream... tcp is a stream - no matter what you want or think. When you want a protocol you have to implement it by your own.
Re: how can i send QStringList index by index
Quote:
Originally Posted by
Validimir_verekno
actually i have a text file.client must send line by line of file to server and server must process line by line of data but client packet many of line and then send to server.
as result server recive many of line and wrong process .
How does the client (sender) know when the server (receiver) is done processing the last line it received? This is the protocol that Christian Ehrlicher is talking about.
The client is essentially a state machine that switches between:
- Send a line
- Wait for signal of completion from server (receive) then go to 1.
Re: how can i send QStringList index by index
SOLVED
thanks to "ChrisW67" & "ChristianEhrlicher"
i find QStreamData : D
QStreamData qsd(socket);
qsd<<File.readLine();