nRF5 SDK is not maintained anymore
More Info: Consider nRF Connect SDK for new designs

Cannot loop send() when trying to send large data in https_client sample on nRF9160

Hi everyone,

I want to send large data with https protocol.

I edited the https_client sample split the data and looped send() for sending the large data.

But when I did send() once, I got error 128. Did the socket close by itself?

After I run send() once, I run close() -> tls_setup() ->connect() again. Then I can do send() again.

This is very time consuming, in a single loop, reconnecting takes 2 or 3 seconds in my environment. So I need a different solution.

Is it possible to loop send() continuously with the socket open? In the past, there have been similar case with the http protocol, but it seems that closing the socket with every send() is the solution.

https://devzone.nordicsemi.com/f/nordic-q-a/46086/nrf9160-dk-http-post-to-my-webserver

Is this still not improving? If I can send quickly even if I close the socket, it may be a solution.

HW:nRF9160DK

FW:modem v1.3.1

SDK v1.9.1

My LTE connection is LTE-M.

Best Regards,

Yukio Oyama

  • Hello

    Looking at the https client sample, it looks like the code is supposed to support sending multiple packets before closing the socket.

    I assume the changes you've made is to limit how many bytes you're allowed to send in each packet? Can you show me the exact changes you've made to the sample?

    Best regards,

    Einar

  • Hello Einar-san,

    This is the minimum set with errors. (Some APN information was hidden.)

    To find the cause, I searched for the smallest change where the error occurred. When sending twice (not loop), an error will occur on the second sending.

    This may be due to server behavior rather than device, but I'm not familiar with either.

    If a socket has been a timeout from open or access, can it be controlled by a parameter in the code?

    In my experiment, send_buff [] is fixed and small in size. Finally, in my project I want to split the image file every 2KB (or less) and upload it by looping the send() .

    Best Regards,

    Yukio Oyama

  • Hello again

    In your code I see that you repeat the whole send-recv procedure when you send the second time. I would not be surprised if the connection is closed server side after handling your recv-request.

    In order to send more while the connection is open, I would instead try to send all your data in the send loop, as you can see from the way the sample code is set up that you are allowed to call send() several times before calling recv(). Does that make sense?

    Best regards,

    Einar

  • Hello Einar-san,

    I wanted to check if the transmitted data was correct every time when I sent the data. But if Recv() causes the socket to close, I would consider changing the way the data is sent.

    I noticed something strange when I was considering this issue.

    I tried increasing the buffer size to send large data. Then, I was able to send 4KB of data if I sent it only once. Of course, I couldn't loop it. However, if I close the socket each time, the 4KB transmission will be reproduced.

    The data size limit for TLS is 2KB.Is it possible to send 4KB only once?

    And does aggressive use of it cause problems in the future?

    Repeating Send() without Recv() will now be confirmed. I will report the results later.

    Best Regards,

    Yukio Oyama

  • Hi

    The size of packets it is possible to send is ultimately limited by available RAM in the modem. This might be more than 2KB depending on your application, but I would still recommend staying within the documented data size limits to guarantee your application will work as you expect.

    Looping send() before calling recv() should work for any buffer size you are able to send though.

    -Einar

Related