I'm currently trying to download some HTTP data from the internet using the uTasker. I used the TCP tutorial that was posted here a while ago as a reference, together with the NTP client code from the demo application.
Definitions...
#define METAF_TCP_PORT 8080
#define MAX_DATA_LEN 500
typedef struct stTCP_MESSAGE
{
TCP_HEADER tTCP_Header; // reserve header space
unsigned char ucTCP_Message[MAX_DATA_LEN]; // data payload space
} TCP_MESSAGE;
const char postData[] = "station_ids=EBAW&std_trans=standard&chk_metars=on&hoursStr=most+recent+only&chk_tafs=on&submitmet=Submit";
static TCP_MESSAGE MetafData;
USOCKET Metaf_TCP_socket;
static unsigned char ucRemoteIP[IPV4_LENGTH] = {204,227,127,34};
My code first obtains a free socket and then performs a connect to the server. So far it's all working fine.
When the connection is successful, the data that is to be sent is created and sent using fnSendTCP. Tracing the code indicates that the data transmission is successful.
Connecting and sending data...
extern void fnMETAF(TTASKTABLE *ptrTaskTable)
{
char printstring[2048];
Metaf_TCP_socket = fnGetTCP_Socket(TOS_MINIMISE_DELAY, TCP_DEFAULT_TIMEOUT, fnMetafListener);
if (Metaf_TCP_socket >= 0)
{
fnTCP_Connect(Metaf_TCP_socket, ucRemoteIP, METAF_TCP_PORT, 0, 0);
strcpy ((char*)MetafData.ucTCP_Message, "POST /metars/index.php HTTP/1.1\r\n");
strcat ((char*)MetafData.ucTCP_Message, "Content-Type: application/x-www-form-urlencoded\r\n");
strcat ((char*)MetafData.ucTCP_Message, "User-Agent: Mozilla/2.0 (compatible; WS4.9e.667)\r\n");
strcat ((char*)MetafData.ucTCP_Message, "Host: adds.aviationweather.gov\r\n");
sprintf (printstring, "Content-Length: %d\r\n", strlen(postData));
strcat ((char*)MetafData.ucTCP_Message, printstring);
strcat ((char*)MetafData.ucTCP_Message, "Cache-Control: no-cache\r\n\r\n");
strcat ((char*)MetafData.ucTCP_Message, postData);
if (fnSendTCP(Metaf_TCP_socket, (unsigned char *)&MetafData, strlen((char*)MetafData.ucTCP_Message), TCP_FLAG_PUSH) > 0)
{
strcpy (printstring, (char*)MetafData.ucTCP_Message); // just some code to put a breakpoint on
}
}
}
The listener code is never reached. Wireshark doesn't indicate a received packet either.
Listener code...
static int fnMetafListener(USOCKET Socket, unsigned char ucEvent, unsigned char *ucIp_Data, unsigned short usPortLen)
{
char printstring[2048];
switch (ucEvent)
{
case TCP_EVENT_ARP_RESOLUTION_FAILED:
break;
case TCP_EVENT_DATA:
// process data
strcpy (printstring, (char*)ucIp_Data);
break;
case TCP_EVENT_CLOSE:
case TCP_EVENT_CLOSED:
case TCP_EVENT_ABORT: // no connection was established
break;
}
return APP_ACCEPT;
}
I have a windows program that sends the same request to the same server and processes the same data. The lines in the trace window that indicate the transmission and reception of the relevant data in Wireshark are all in green. The lines that come from the uTasker are all grey though. Also, the packets that come from the uTasker don't contain the data that I'm trying to send and don't have the PUSH flag set either.
There is obviously something not being done right here. Any help is appreciated!