Hi Mark, although this is related to my "newbie" thread, I wanted to post here since it's related to TCP. I am not an experienced network programmer by any means. Most of the code I have written on Windows to program sockets uses really high level .NET libraries and aren't ever used in production code.
In order to get myself familiarized with sockets on uTasker, I felt that a reasonable starting point would be to leverage the simulator and modify the fnMyFirstTask() function from the getting started guide. Here's what I ended up with:
extern void fnMyFirstTask(TTASKTABLE *ptrTaskTable)
{
static unsigned char ucCounter = 0;
/*
fnDebugMsg("Hello, World! Test number ");
fnDebugDec(ucCounter++, 0);
fnDebugMsg("\r\n");
*/
static unsigned char ucRemoteIP[IPV4_LENGTH] = {192,168,0,112};
unsigned char data[MIN_TCP_HLEN + 4];
//memset( data, 0, 1024);
USOCKET test_client_socket = fnGetTCP_Socket(TOS_MINIMISE_DELAY, TCP_DEFAULT_TIMEOUT, fnTestTcpServerConnect);
if (test_client_socket >= 0) {
USOCKET ret;
if( (ret = fnTCP_Connect(test_client_socket, ucRemoteIP, 50000, 0, 0)) > 0) {
fnDebugMsg( "connected\r\n");
if( fnSendTCP(test_client_socket, data, 4, TCP_FLAG_PUSH) > 0) {
fnDebugMsg( "sent successfully\r\n");
} else {
fnDebugMsg( "send failed\r\n");
}
fnReleaseTCP_Socket( test_client_socket);
} else {
if( ret == SOCKET_NOT_FOUND)
fnDebugMsg( "Socket not found\r\n");
else if( ret == NO_FREE_PORTS_AVAILABLE)
fnDebugMsg( "No free ports available\r\n");
else if( ret == SOCKET_STATE_INVALID)
fnDebugMsg( "Socket state invalid\r\n");
}
} else {
if( test_client_socket == -2) {
fnDebugMsg( "No socket available\r\n");
}
}
}
I have the task set up to start after 10s and call fnMyFirstTask() every 10s. This gives me enough time after starting the application to select the right NIC from the uTasker dialog.
I wrote a simple listener app in C# that listens on port 50000. I know this app works because I have some code running on my FRDM-K64F that connects to the port and streams it data. I can see the connection occur and bytes coming in.
When I run my application, via Telnet I can see that the socket gets created and connects successfully, and supposedly data is also sent successfully. However, my app doesn't see the connection or byte stream. On top of that, Wireshark reports some kind of error:
105964 4274.560943000 192.168.0.88 192.168.0.112 TCP 58 [TCP Out-Of-Order] 64416?50000 [SYN, PSH] Seq=0 Win=1460 Len=0
From reading the past posts in this thread, it sounds like it's possible that data could be sent, but not actually get received due to things like ACKs not being sent? Anyhow, I put breakpoints in fnTestTcpServerConnect() and none of them get hit. Actually, the function seems to not ever get called.
Can you provide me with any suggestions on debugging this further? Can you also recommend any good reads for people that don't understand the nitty-gritty details of TCP, but want to learn?
Thank you!