Reputation: 15
I am unable to receive the response to multiple HTTP requests when I attempt to enqueue data to send to a server.
We are able to establish a connection to a server and immediately issue an HTTP request inside the connected_callback() function (called as soon as a connection to the server is established) using the tcp_write() function. However, if I attempt to generate two HTTP resquests or more using the following syntax:
err_t connected_callback(void *arg, struct tcp_pcb *tpcb, err_t err) {
xil_printf("Connected to JUPITER server\n\r");
LWIP_UNUSED_ARG(arg);
/* set callback values & functions */
tcp_sent(tpcb, sent_callback);
tcp_recv(tpcb, recv_callback);
if (err == ERR_OK) {
char* request = "GET /circuits.json HTTP/1.1\r\n"
"Host: jupiter.info.polymtl.ca\r\n\r\n";
(void) tcp_write(tpcb, request, 100, 1);
request = "GET /livrable1/simulation.dee HTTP/1.1\r\n"
"Host: jupiter.info.polymtl.ca\r\n\r\n";
(void) tcp_write(tpcb, request, 100, 1);
tcp_output(tpcb);
xil_printf("tcp_write \n");
} else {
xil_printf("Unable to connect to server");
}
return err;}
I manage to send all of the data to the server, but I never receive any data for the second HTTP request. I manage to print the payload for the first request (the JSON file) but I never manage to receive anything for the .dee file. Are there any specific instructions to enqueue HTTP requests together with lwIP or am I missing something?
If you require any more code to accurately analyze my problem, feel free to say so.
Thanks!
Upvotes: 0
Views: 1133
Reputation: 230
I found myself in this exact same situation and landed here from google to find no answers.
After a few hours I found that if I close tcb and re open it in between the 2 calls it worked fine.
I don't no if that is best way to go about things, but it got it working.
char* request = "GET /circuits.json HTTP/1.1\r\n"
"Host: jupiter.info.polymtl.ca\r\n\r\n";
(void) tcp_write(tpcb, request, 100, 1);
tcp_sent(tpcb, NULL);
tcp_recv(tpcb, NULL);
err_t err = tcp_close(tpcb);
tpcb = tcp_new_ip_type(IP_GET_TYPE(&remote_addr));
tcp_sent(tpcb, send_callback);
tcp_recv(tpcb, recv_callback);
err_t err = tcp_connect(tpcb, &remote_addr, TCP_PORT, tcp_client_connected);
request = "GET /livrable1/simulation.dee HTTP/1.1\r\n"
"Host: jupiter.info.polymtl.ca\r\n\r\n";
(void) tcp_write(tpcb, request, 100, 1);
Upvotes: 0
Reputation: 7441
The problem I see is that you have double \r\n
combination at the end of your request header statement.
You need \r\n\r\n
only at the end of your header. Now, you have double times. Remove from first write.
Upvotes: -1