Home > Mobile >  Strange problems encountered in the process of using tcpsocket readall function
Strange problems encountered in the process of using tcpsocket readall function

Time:09-17

Dear leaders, I have the following problems:
I'll TCP client USES signal readyread () trigger slot function to receive data, the data transmission arise when readall receive less than the problem of data, can be seen through caught data has been sent, but I call readall read out of the total number of bytes with a file number of bytes in (using the internal cache data read by several times, application, sometimes I have found that the socket read buffer is full, but my side readall still can't read data, readyread also don't continue to trigger, program does not run in whlie cycle,

CodePudding user response:

By wireshark caught found that when there is a window full of TCP, the buffer is full readall first receive a piece of data is small, then the readyread will not be triggered

CodePudding user response:

Can calculate first file size, waiting for receiving enough in the loop

CodePudding user response:

I was through the event loop to receive packages, the file size of calculation has been completed, the key is to readall get data for the
reference
to calculate file size, waits to receive enough in stop cycle

CodePudding user response:

I encountered a similar before, you see if the same situation:
1, the sender sends to complete 500 KB,
2, the receiver receive readReady, hence I readAll, but can take to more than 200 KB

Finally my solution:
1, the sender sends first need to send the file size of
2, the sender sends file
3, the receiver to receive the file size, to save file size fileSize global;
4, the receiver trigger readReady again, judge bytesAvailable (), if less than the FileSize, exit function directly, do not read, until a certain size is equal to the FileSize again read

CodePudding user response:

reference
I encountered a similar before, you see if the same situation:
1, the sender sends to complete 500 KB,
2, the receiver receive readReady, hence I readAll, but can take to more than 200 KB

Finally my solution:
1, the sender sends first need to send the file size of
2, the sender sends file
3, the receiver to receive the file size, to save file size fileSize global;
4, the receiver trigger readReady again, judge bytesAvailable (), if less than the FileSize, exit function directly, do not read, until a certain size is equal to the FileSize again read



Is not similar with you because I need to transfer the file large is bigger than the socket buffer may not like you don't read
I have signal processing are: trigger is read, the same file size I have saved, determine whether to read data is complete, but I appeared the following situation:
Data has not received up, still waiting to receive the complete data, I use wireshark caught see the same data has been sent to me, and large amount of data window will appear full, that is, the buffer is full, but I don't side readyread signal has been triggered, I set the timer in the program, timing to readall () to the data, but will keep readall got zero bytes,
I wonder if the socket buffer is full of readyread signal has not triggered, ps: program into an infinite loop, groove trigger signal is normal

CodePudding user response:

I don't suggest you use your said on the fourth floor to the fourth data to the specified size is not read, you can read the first saved, because the socket buffer can not stand you so play,

CodePudding user response:

Not super, I sent a few G files, also no problem, every time I send only 500 k, can't more than buffer limit, I only read only up to 500 k

CodePudding user response:

Said before is wrong, not judge fileSize, is sent every time the size of the judgment

CodePudding user response:

Every time send before you send the size to send data, every time I send 500 k, 500 k this size before you send the data to send in the past, the receiver does not read before storage to 500 k

CodePudding user response:

Strange to say my computer code in colleagues can perfect and I'll break appear afore-mentioned problems,
You the scheme is desirable, apparent problems can be circumvented I said, now I decided to use SFTP for file transfer,
I just want to understand the reason why I said the problem, and thank you for your answer,
  •  Tags:  
  • Qt
  • Related