#171395 - Ant6n - Wed Nov 18, 2009 8:40 am
Hio,
In some project I need to send possibly up to like 500KB at the time, which I thought would not be a problem using today's ultra speeds of wifi's and dsl's. I use the http example from devkitpro with POST to get the data onto my server.
In other threads there is mention that 'send' only sends ~8K data at a time, so I do the resend trick, with a swiWaitForVBlank thrown in for good measure. The final code looks like this
The first time it sends 8K, then a bit less than 2K, apparently going down to about 1K, then it stops submitting. It doesn't always behave the same way. When I try with smaller data (~14K), it finishes succesfully and prints the result from the server. Ideas?
In some project I need to send possibly up to like 500KB at the time, which I thought would not be a problem using today's ultra speeds of wifi's and dsl's. I use the http example from devkitpro with POST to get the data onto my server.
In other threads there is mention that 'send' only sends ~8K data at a time, so I do the resend trick, with a swiWaitForVBlank thrown in for good measure. The final code looks like this
Code: |
char * url = "<host>"; char* request = "POST /<user>/cgi-bin/DSWifiSubmit.py HTTP/1.1\r\n" "<host>\r\n" "Content-Length: %d\n" "\n" "recording=%s"; int getHttp(char* url,char *request_text) { int success = 0; pause_terminal();//pause terminal -- sending might get disrupted by interrupts // Find the IP address of the server, with gethostbyname struct hostent * myhost = gethostbyname( url ); iprintf("Found IP Address, "); // Create a TCP socket int my_socket; my_socket = socket( AF_INET, SOCK_STREAM, 0 ); iprintf("Created Socket"); // Tell the socket to connect to the IP address we found, on port 80 (HTTP) struct sockaddr_in sain; sain.sin_family = AF_INET; sain.sin_port = htons(80); sain.sin_addr.s_addr= *( (unsigned long *)(myhost->h_addr_list[0]) ); connect( my_socket,(struct sockaddr *)&sain, sizeof(sain) ); iprintf("Connected to server,sending data"); // send our request - it only sends ~8k(?) bytes at a time int sent = 0, size = strlen(request_text); while(sent < size){ printf("sent %d of %d bytes\n",sent,size); sent += send(my_socket, &(request_text[sent]), size - sent, 0); swiWaitForVBlank(); } printf("sent %d of %d bytes\n",sent,size); iprintf("Sent data, printing result:\n"); int recvd_len; char incoming_buffer[256]; while( ( recvd_len = recv( my_socket, incoming_buffer, 255, 0 ) ) != 0 ) { // if recv returns 0, the socket has been closed. if(recvd_len>0) { // data was received! incoming_buffer[recvd_len] = 0; // null-terminate iprintf(incoming_buffer); resume_terminal();//reactivate terminal nextDownEvent(); pause_terminal();//pause terminal -- sending might get disrupted by interrupts } } resume_terminal();//reactivate terminal iprintf("\nclosed connection\n"); shutdown(my_socket,0); // good practice to shutdown the socket. iprintf("shutdown socket, "); closesocket(my_socket); // remove the socket. iprintf("closed socket\n"); success = 1; return success; } |
The first time it sends 8K, then a bit less than 2K, apparently going down to about 1K, then it stops submitting. It doesn't always behave the same way. When I try with smaller data (~14K), it finishes succesfully and prints the result from the server. Ideas?