PDA

View Full Version : how can i send QStringList index by index



Validimir_verekno
20th June 2021, 10:33
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"

ChristianEhrlicher
20th June 2021, 13:34
And what's the actual problem? The server received all the data or didn't it?

Validimir_verekno
20th June 2021, 15:29
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"

ChristianEhrlicher
20th June 2021, 16:03
tcp is stream-based... so I don't see what's wrong here.

Validimir_verekno
21st June 2021, 18:26
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

ChristianEhrlicher
21st June 2021, 19:14
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.

ChrisW67
22nd June 2021, 08:19
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.

Validimir_verekno
22nd June 2021, 18:25
SOLVED
thanks to "ChrisW67" & "ChristianEhrlicher"
i find QStreamData : D
QStreamData qsd(socket);
qsd<<File.readLine();