Hello,
I am using the TI-RTOS NDK stack to connect from a PC to a TM4C129 microcontroller over a TCP/IP socket connection. I am using a socket test app on the PC side.
I am able to establish connection when the PC is the server (accepts connection from the microcontroller) and the microcontroller is the client (uses the connect API).
However, when the PC is the client (attempts to connect to the microcontroller) and the microcontroller is the server (creates socket, binds, listens, then tries to accept), the microcontroller blocks at the accept() function and never sees a connection request from the PC.
Is there something in my code below that could be causing this? The only difference between this code and the TI example application (enet_tcpecho_server_tirtos) is that I am configuring my microcontroller to be using a static IP instead of being assigned one via DHCP. Could this have something to do with the problem?
Notes:
- Program below blocks at accept and never prints "Accept socket success" (does not hit break statement either).
- I enabled local and remote TCP ports on my PC firewall to make sure it was not a firewall issue.
Microcontroller as the server code:
serverListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (serverListenSocket == SOCKET_ERROR)
{
break;
}
System_printf("Create socket success.\n");
System_flush();
memset(&localAddress, 0, sizeof(localAddress));
localAddress.sin_family = AF_INET;
localAddress.sin_addr.s_addr = inet_addr("192.168.1.20");
localAddress.sin_port = htons(50000);
status = bind(serverListenSocket, (struct sockaddr *)&localAddress, sizeof(localAddress));
if (status != 0)
{
break;
}
System_printf("Bind socket success.\n");
System_flush();
// TODO - Change maxcon argument to constant
status = listen(serverListenSocket, 3);
if (status != 0)
{
break;
}
System_printf("Listen socket success.\n");
System_flush();
// TODO - Accept connection from remote host
clientSocket = accept(serverListenSocket, (struct sockaddr *)&clientAddress, &clientAddressLen);
if (clientSocket == (int)INVALID_SOCKET)
{
break;
}
System_printf("Accept socket success.\n");
System_flush();
IP Address portion of Config File: