Home > Mobile >  Why in the qt socket communication so difficult?
Why in the qt socket communication so difficult?

Time:09-17

Intention is to put the suffix for CSV file line sent to the server, the server readData function triggers only once to accept the client
Send 15 lines, that is why, bosses (sent common file is bad, the server receives the data format is I write dead)

The result is: the server info only send the data of the first line, and buf has 15 lines,
Morally server info should be print 15 times every time is different content (client for loop 15)

Void dealclient: : readData ()//server, have data to perform
{
QByteArray buf=m_socket - & gt; ReadAll ();
Qint64 operation=QString (buf). Section (" # # ", 0, 0), toInt ();

If (operation==4)
{
QDebug () & lt; <"Open the file \ n";
Bool isOk=file. Open (QIODevice: : WriteOnly | QIODevice: : Append);
If (false==isOk)
{
QDebug () & lt; <" The file open error 49 ";
return;
}
QDebug () & lt; <" 123456 ";
QString info=QString (buf). Section (" # # ", 1, 1);

Qint64 len=file. Write (buf);
QDebug () & lt; QDebug () & lt; QDebug () & lt; <"Close the file \ n";
File. The close ();

}
}
Void exam_freezing: : SendData publishes the event (QTcpSocket * socket)//client
{
Qint64 operation=4;
for(int i=0; I & lt; 15. I++)
{

QString line=choice_string_list. At (I) + "\ n";
QString info=QString (" % 1 # # % 2 "). Arg (operation). Arg (line);
The socket - & gt; Write (info. ToLocal8Bit ());
If (socket - & gt; WaitForBytesWritten ()==false)
{
Usleep (1000);
}
QDebug () & lt; }
}

CodePudding user response:

To understand the qt event loop this thing, you only enters the event loop can really put the data sent out, you have been sleep, of course not sent out
  •  Tags:  
  • Qt
  • Related