how to resolve packet loss issue?

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

Re: how to resolve packet loss issue?

Postby alvin_xie » Mon Jun 25, 2018 1:14 am

fly135 wrote: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

Code: Select all

			count = strlen(recvbuf);	//recvbuf  //test_pic
			to_write = strlen(recvbuf);
			g_total_data = 0;
			while (count > 0) {
				len = send(connect_socket, recvbuf  + (to_write - count), EXAMPLE_DEFAULT_PKTSIZE, 0x18);	//recvbuf ->test_pic	//0x10: more;  0x08:do not block
				if(len == -1) {
					//ESP_LOGI(TAG, "transmit error .error_cnt:%d", error_cnt);
					//vTaskDelay(10 / portTICK_RATE_MS);
					error_cnt++;
					if(error_cnt > 2000)
						break;
					else
						continue;
				}
					//send(connect_socket, recvbuf  + (to_write - count), EXAMPLE_DEFAULT_PKTSIZE, 0);
				if (len > 0) {
					g_total_data += len;
					count -= len;
					//ESP_LOGI(TAG, "len  %d, count :%d \r\n" , len, count);
				}else {
					int err = get_socket_error_code(connect_socket);
					ESP_LOGI(TAG, "line 190 err = %d", err);
#if EXAMPLE_ESP_TCP_PERF_TX && EXAMPLE_ESP_TCP_DELAY_INFO
					g_send_fail++;
#endif
					ESP_LOGI(TAG, "len  %d \r\n" , len);

					if (err != ENOMEM) {
						show_socket_error_reason("send_data", connect_socket);
						ESP_LOGI(TAG, "error = %d ..\r\n",show_socket_error_reason("send_data", connect_socket));
						break;
					}
				}


			}

Is it ok?
If the send flag is 0, return of send is 1460(size of 1 packet)
If the send flag is 0x18, return of send is -1 sometimes.

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 » Tue Jun 26, 2018 11:46 pm

One thing I notice right off the bat is that you are always trying to send EXAMPLE_DEFAULT_PKTSIZE bytes. If the amount left to send is less than EXAMPLE_DEFAULT_PKTSIZE, but more than zero you will send data that isn't mean to be sent.

amount_to_send = (to_write < EXAMPLE_DEFAULT_PKTSIZE)?to_write:EXAMPLE_DEFAULT_PKTSIZE;

Also you are assuming that the data is zero terminated strings, so that's what they better be.

John A

jens.alfke
Posts: 17
Joined: Wed May 02, 2018 4:26 pm

Re: how to resolve packet loss issue?

Postby jens.alfke » Thu Jun 28, 2018 4:23 pm

I've never seen anyone use send() to write to a TCP socket! TCP is a stream, so you use write() to write to it and read() to read. The only time I would use send() is for UDP.

I have no idea what happens if you call send() instead of write(). It may well skip part of the TCP logic and send the packet directly instead of going through vital logic like buffering and flow control ... which would probably produce results like what you're seeing, since IP packets are lossy.

Try looking up a network socket tutorial and following what it does.

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 » Thu Jun 28, 2018 9:15 pm

send works. Surprised you didn't look it up yourself before posting that the guy should look it up.

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

Re: how to resolve packet loss issue?

Postby alvin_xie » Mon Jul 16, 2018 1:57 am

the ESP-IDF packet is got from github,the send() is a package of write(), and the example of tcp_perf also use send() to write the file to the server.

Who is online

Users browsing this forum: Baidu [Spider] and 87 guests