<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Data loss occurs when using TCP to send data on the nRF7002 DK.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/126243/data-loss-occurs-when-using-tcp-to-send-data-on-the-nrf7002-dk</link><description>Hi 
 I am using the nRF7002 DK with NCS 2.7, based on the sample project `nrf70-wifi-ble-image-transfer-demo`. I modified the code to embed a fixed image as a header file stored in flash memory, and then used a function to transmit the entire image via</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 06 Jan 2026 11:22:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/126243/data-loss-occurs-when-using-tcp-to-send-data-on-the-nrf7002-dk" /><item><title>RE: Data loss occurs when using TCP to send data on the nRF7002 DK.</title><link>https://devzone.nordicsemi.com/thread/558013?ContentTypeID=1</link><pubDate>Tue, 06 Jan 2026 11:22:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ff5a27dc-c399-4036-a083-89d10f48e4e8</guid><dc:creator>Benjamin</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I had a look at your code. The reason is that the send function may send fewer bytes than requested. This is normal behavior when working with TCP. TCP is a byte stream protocol, so partial sends are expected. It is correct to repeatedly call send until all data has been sent, as you’ve done in the second function.&lt;br /&gt;&lt;br /&gt;Regards,&lt;br /&gt;Benjamin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Data loss occurs when using TCP to send data on the nRF7002 DK.</title><link>https://devzone.nordicsemi.com/thread/557972?ContentTypeID=1</link><pubDate>Tue, 06 Jan 2026 02:13:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69c6d6f1-429b-4def-b590-26115159a874</guid><dc:creator>Ziyao Zhou</dc:creator><description>[deleted]&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Data loss occurs when using TCP to send data on the nRF7002 DK.</title><link>https://devzone.nordicsemi.com/thread/557951?ContentTypeID=1</link><pubDate>Mon, 05 Jan 2026 15:47:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e140fa8d-e00b-41d0-9134-7ab993dbc0e8</guid><dc:creator>Benjamin</dc:creator><description>[deleted]&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Data loss occurs when using TCP to send data on the nRF7002 DK.</title><link>https://devzone.nordicsemi.com/thread/557706?ContentTypeID=1</link><pubDate>Tue, 30 Dec 2025 01:45:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e79ce4c6-2d52-47bd-921c-e4f9f9bb4177</guid><dc:creator>Ziyao Zhou</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;ChatGPT ask me to change cam send&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;from&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void cam_send(const void *buf, size_t len){
		#if defined(CONFIG_SAMPLE_SCOKET_TCP)
			if (send(tcp_server_socket, buf, len, 0) == -1) {
				perror(&amp;quot;Sending failed&amp;quot;);
				close(tcp_server_socket);
				FATAL_ERROR();
				return;
			}
		#else
			sendto(udp_socket, buf, len, 0, (struct sockaddr *)&amp;amp;pc_addr,  sizeof(pc_addr));
		#endif
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;to&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void cam_send(const void *buf, size_t len){
    #if defined(CONFIG_SAMPLE_SCOKET_TCP)
        size_t total_sent = 0;
        int retry_count = 0;
        const int MAX_RETRIES = 3;
        
        while (total_sent &amp;lt; len &amp;amp;&amp;amp; retry_count &amp;lt; MAX_RETRIES) {
            ssize_t sent = send(tcp_server_socket,
                               (uint8_t*)buf + total_sent,
                               len - total_sent, 0);
            if (sent == -1) {
                if (errno == EAGAIN || errno == EWOULDBLOCK) {
                    // 缓冲区满，稍后重试
                    k_sleep(K_MSEC(10));
                    retry_count++;
                    continue;
                }
                // 其他错误，连接断开
                perror(&amp;quot;Sending failed&amp;quot;);
                close(tcp_server_socket);
                return;
            }
            total_sent += sent;
            retry_count = 0; // 成功发送后重置重试计数
        }
        
        if (total_sent &amp;lt; len) {
            LOG_ERR(&amp;quot;Failed to send all data after retries&amp;quot;);
        }
    #else
        sendto(udp_socket, buf, len, 0, (struct sockaddr *)&amp;amp;pc_addr, sizeof(pc_addr));
    #endif
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The the data loss will be sloved. But I am not so sure about why this will work.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Data loss occurs when using TCP to send data on the nRF7002 DK.</title><link>https://devzone.nordicsemi.com/thread/557568?ContentTypeID=1</link><pubDate>Tue, 23 Dec 2025 10:17:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c81e0823-25d1-4f7b-8b5d-907be29b5ee6</guid><dc:creator>Benjamin</dc:creator><description>&lt;p&gt;Hi Zhou,&lt;br /&gt;&lt;br /&gt;&lt;span&gt;Thanks for reaching out, we are currently understaffed due to Christmas holidays. Answers may take longer.&lt;br /&gt;&lt;br /&gt;I am starting to look into this, we&amp;#39;ll come back to you when I have an update.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Benjamin&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>