how to resolve packet loss issue?

alvin_xie
Posts: 17
Joined: Fri May 11, 2018 1:48 am

how to resolve packet loss issue?

Postby alvin_xie » Thu Jun 21, 2018 11:28 am

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!
Last edited by alvin_xie on Fri Jun 22, 2018 12:23 am, edited 1 time in total.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: how to resolve packet loss issue?

Postby kolban » Thu Jun 21, 2018 2:18 pm

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()?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

alvin_xie
Posts: 17
Joined: Fri May 11, 2018 1:48 am

Re: how to resolve packet loss issue?

Postby alvin_xie » Fri Jun 22, 2018 12:30 am

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.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: how to resolve packet loss issue?

Postby kolban » Fri Jun 22, 2018 12:52 am

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.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: how to resolve packet loss issue?

Postby fly135 » Fri Jun 22, 2018 1:01 am

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

alvin_xie
Posts: 17
Joined: Fri May 11, 2018 1:48 am

Re: how to resolve packet loss issue?

Postby alvin_xie » Fri Jun 22, 2018 1:24 am

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.

alvin_xie
Posts: 17
Joined: Fri May 11, 2018 1:48 am

Re: how to resolve packet loss issue?

Postby alvin_xie » Fri Jun 22, 2018 1:34 am

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,

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: how to resolve packet loss issue?

Postby fly135 » Fri Jun 22, 2018 4:44 pm

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

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: how to resolve packet loss issue?

Postby WiFive » Fri Jun 22, 2018 6:40 pm

count = total
to_write = remaining
to_write -= len

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: how to resolve packet loss issue?

Postby fly135 » Fri Jun 22, 2018 8:43 pm

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.

Who is online

Users browsing this forum: and3rson and 129 guests