Mark,
I've just used the demo code at the head of this post to test how to handle TCP and I found a number of typo's, I'm mentioning them here so you can amend the code listing so others don't have the same problems I did. The errors are as follows
1. The Code below has an extra }
case TCP_EVENT_CLOSED:
fnTCP_Listen(Socket, ++usTestPort, 0); // go back to listening state on next port number
break;
}
should be
case TCP_EVENT_CLOSED:
fnTCP_Listen(Socket, ++usTestPort, 0); // go back to listening state on next port number
break;
2. In the following code test_message->tTCP_Header should be test_message.tTCP_Header
case TCP_EVENT_DATA:
if ((ucEvent == TCP_EVENT_REGENERATE) || (!uMemcmp((CHAR*)ucIp_Data, "TEST" , 4))) {
uStrcpy((CHAR*)test_message.ucTCP_Message, "Hi!!");
if (fnSendTCP(Socket, (unsigned char *)&test_message->tTCP_Header, 4, TCP_FLAG_PUSH) > 0) {
return APP_SENT_DATA;
}
}
should be
case TCP_EVENT_DATA:
if ((ucEvent == TCP_EVENT_REGENERATE) || (!uMemcmp((CHAR*)ucIp_Data, "TEST" , 4))) {
uStrcpy((CHAR*)test_message.ucTCP_Message, "Hi!!");
if (fnSendTCP(Socket, (unsigned char *)&test_message.tTCP_Header, 4, TCP_FLAG_PUSH) > 0) {
return APP_SENT_DATA;
}
}
3. In the start-up code you suggest using
USOCKET Test_socket = fnGetTCP_Socket(TOS_MINIMISE_DELAY, (unsigned short)10, fnTestListener);
This should be
USOCKET Test_socket = fnGetTCP_socket(TOS_MINIMISE_DELAY, (unsigned short)10, fnTestListener);
Note the lowercase s in fnGetTCP_socket
Looking at tcpip.h it seems the case of the function words after a _ symbol is a bit random, for example
extern USOCKET fnGetTCP_Socket(unsigned char ucTos, unsigned short usIdleTimeout, int (*listener)(USOCKET, unsigned char, unsigned char *, unsigned short) );
extern USOCKET fnGetUDP_socket(unsigned char ucTOS, int (*fnListener)(USOCKET, unsigned char, unsigned char *, unsigned short, unsigned char *, unsigned short), unsigned char ucOpts);
extern USOCKET fnReleaseUDP_socket(USOCKET SocketHandle);
extern USOCKET fnReleaseTCP_Socket(USOCKET TCPSocket);
I hope the above helps
Cheers
Martin