Page 1 of 2

how to resolve packet loss issue?

Posted: Thu Jun 21, 2018 11:28 am
by alvin_xie
Use TCP socket.
I use this function "len = send(connect_socket, recvbuf + (count - to_write), to_write, 0);" to send data to PC server.(recvbuf almost 20~30KB)
Sometimes, It seems that the function "send" return ok. But the data that PC server got has lost some packet.
How could i resolve this issue?
Thanks!

Re: how to resolve packet loss issue?

Posted: Thu Jun 21, 2018 2:18 pm
by kolban
Not really enough to go here (opinion). Is this a TCP or UDP socket? What makes you think that packets get lost? Are you checking the return code from send()?

Re: how to resolve packet loss issue?

Posted: Fri Jun 22, 2018 12:30 am
by alvin_xie
kolban wrote:Not really enough to go here (opinion). Is this a TCP or UDP socket? What makes you think that packets get lost? Are you checking the return code from send()?
Compare the file before send and received, it is different.The file has lost some string after received.

Re: how to resolve packet loss issue?

Posted: Fri Jun 22, 2018 12:52 am
by kolban
Over multiple tests, is it the same "piece" of the received file that differs from the original file? Can we tell where data is being lost? Are you logging the lengths of received data and sent data? I'd like to determine whether the problem is in transmitting data or writing files. For example, if the file writing wasn't correct then that may also manifest as missing data. If we can see a match between sent data size and received data size that might be very useful.

Re: how to resolve packet loss issue?

Posted: Fri Jun 22, 2018 1:01 am
by fly135
Maybe it's the program on the PC. Maybe it times out on a recv and closes the file instead of trying another read. Maybe somebody set the recv timeout too low and thought any non ok return meant it was done. Hard to tell from the description of the problem.

John A

Re: how to resolve packet loss issue?

Posted: Fri Jun 22, 2018 1:24 am
by alvin_xie
kolban wrote:Over multiple tests, is it the same "piece" of the received file that differs from the original file? Can we tell where data is being lost? Are you logging the lengths of received data and sent data? I'd like to determine whether the problem is in transmitting data or writing files. For example, if the file writing wasn't correct then that may also manifest as missing data. If we can see a match between sent data size and received data size that might be very useful.
Over multiple tests, is it the same "piece" of the received file that differs from the original file?
-->the file is different ever time, and the "piece" of the received file that differs from the original file is not the same.
PC use a sockettool to recevie. ESP32 send function return the right lenth(the return value of "send" is the size of file),but PC sockettool do not get the right lenth.

Re: how to resolve packet loss issue?

Posted: Fri Jun 22, 2018 1:34 am
by alvin_xie
fly135 wrote:Maybe it's the program on the PC. Maybe it times out on a recv and closes the file instead of trying another read. Maybe somebody set the recv timeout too low and thought any non ok return meant it was done. Hard to tell from the description of the problem.

John A
PC use a sockettool creat TCP server,ESP32 use as client, connect to PC TCP server, and send a 20-30KB file,(file is a picture,BASE64 format).
use function "len = send(connect_socket, recvbuf + (count - to_write), to_write, 0);" , the len return the right sizeof "recvbuf".
But sometimes PC server do not get enough length of the file that ESP32 send.
note: ESP32 and PC connected to the same Router.
Is it clearly description?
Thanks,

Re: how to resolve packet loss issue?

Posted: Fri Jun 22, 2018 4:44 pm
by fly135
I stared at this for a while and can't figure out the logic....

"len = send(connect_socket, recvbuf + (count - to_write), to_write, 0);"

Assuming the recvbuf is actually the sendbuf, and assuming you are in some loop sending "to_write" number of bytes each time, I can't understand how "recvbuf + (count - to_write)" is computing the pointer of the buffer to send.

John A

Re: how to resolve packet loss issue?

Posted: Fri Jun 22, 2018 6:40 pm
by WiFive
count = total
to_write = remaining
to_write -= len

Re: how to resolve packet loss issue?

Posted: Fri Jun 22, 2018 8:43 pm
by fly135
WiFive wrote:count = total
to_write = remaining
to_write -= len
Makes sense now. to_write = count in the beginning and decremented by len for each send. :)

Without seeing the rest of the code that escaped me.