We are using over own server that host multiple apis for different functionalities.
I am able to make http post requests to all of them individually and everything works fine.
For efficient flow of the program (more importantly from power consumption stand point) it is much better if I can open one socket connection to our server and send multiple http post requests one after and another and then close the connection (socket) at the end. This is where I am facing a challenge.
This works:
create a socket, connect, send for 1st api, close socket .... create a socket, connect, send for 2nd api, close socket .... create a socket, connect, send for 3rd api, close socket
What does not work:
create a socket, connect, send for 1st api, send for 2nd api, send for 3rd api, close socket
when sending the 2nd http post data, i get a 128 error (ENOTCONN 128 /* Socket is not connected */).
I have tried with keep-alive in my request header but that waits for 5-10 seconds after sending before a response is received from our server (which is a big NO for power consumption)
here is my header:
"POST /api1/HTTP/1.1\r\n"\
"Host: xxx.com \r\n"\
"Connection: keep-alive\r\n"\
"Content-Type: application/json\r\n"\
"Content-Length: %d\r\n\r\n"\
"%s\r\n"
Thanks in advance!