Community news, upcoming events and general discussions
Threads: 30 Posts: 77
Get technical support from the community
Threads: 909 Posts: 4927
Threads: 15 Posts: 54
Tell us how to make XDK better!
Threads: 34 Posts: 112
Share and discuss community member projects
Threads: 37 Posts: 172
I'm trying to send HTTP POST request every second. I'm playing with HttpExampleClient provided with XDK. The only things I changed are wifi credentials, receiving server host and port, and sending interval(1000ms). I also added wifi connection check before every request.
It usually starts OK, but after 5-10 min I start getting Failed HttpClient_initRequest from time to time for a period 10-60s. Then i gets OK again. I tried different receiving servers with the same result.
Hello Juri, First, I would like to welcome you to the XDK community. As for your issue, the HTTP implementation currently has two limitations in regards to initializing requests. The first is the number of requests that can exist at any point in time, which is exactly one. Secondly, releasing messages (i.e. allowing the next message) is done automatically by a garbage collector, which is part of the ServalStack library. This garbage collector will collect a message every 1000ms. Given your application's period of 1000ms, these times may collide. Generally, the only case where I see the function HttpClient_initRequest() failing is the case where another message already exists. I would recommend to verify if a response to the latest message had actually been received. The message will most likely be still regarded as active, if the server is not sending the response immediately and decides to keep the connection open. Of course, it could also be the case that the XDK did not send the previous message yet. I would recommend to verify that as well. And if both cases are not given, I would set the period slightly higher (such as 1200-1500ms), and see if that has any effect. Please tell me if this was helpful and feel free to ask further questions. Kind regards, Franjo
Hello Juri, Uunfortunately, it does not seem to be the case that the HTTP allows to set a timeout for receiving a response. The library effectively hides anything of the socket-level implementation. If you require optimization on this matter, the only option for optimization may be reimplementing HTTP on socket level, at least if the optimization is required. Please tell me if this was helpful, and do not hesitate to ask further questions. Kind regards, Franjo
Is there's also a limit on the POST request body size? I don't get any response whenever payload string is longer than 908 bytes.
I tried to use chunked payload writing ( like in HTTP guide writeNextPartToBuffer). But the problem persists with the same length.
Recv callback is called but not Resp.
Hello Juri, due to limitations of the API, there is no possibility to use chunked transfer encoding with the ServalStacks HTTP implementation. Especially since this is a 3rd-party library, there is no workaround for that. What you refer to as chunked payload writing only refers to the initial buffer which is used for sending one message. Additionally, I assume that the payload size for the entire HTTP message may be 1024 bytes. Exceeding that limit may also lead to unexpected behaviour, and as the code of the ServalStack is hidden, I cannot precisely pinpoint what behaviour is intended. What kind of data are you sending? Perhaps, if you tell me about your use case, I might be able to help find a different solution. But generally, if you wish to avoid the limitations of the HttpExampleClient example, you could use the simplelink API. This one is more powerful, but also as low level as it can get, since it is only one step above of the Wi-Fi chip's driver commands. Kind regards, Franjo