If it helps, here is the majority of the code. LOG() is a message logging routine - mostly just prints to the debug console. PEND_CHECK() and UPEND_CHECK are just pended and unpended generic status checkers that will log a message using LOG. PEND will hang if status is not 0.
/* Create a socket. */
status = nx_tcp_socket_create(&ip_0, &tcpSocket, (CHAR *) "Echo Server Socket",
NX_IP_NORMAL, NX_FRAGMENT_OKAY, NX_IP_TIME_TO_LIVE, 512, NX_NULL, NX_NULL);
PEND_CHECK(status, "Socket Create");
/* Bind the port to the TCP socket */
status = nx_tcp_client_socket_bind(&tcpSocket, CLIENT_SOCKET, NX_WAIT_FOREVER);
PEND_CHECK(status, "Socket Bind");
LOG(MESSAGE_PRIORITY_MEDIUM, "Trying socket disconnect first...");
status = nx_tcp_socket_disconnect(&tcpSocket, 400);
UPEND_CHECK(status, "Socket Disconnect");
LOG(MESSAGE_PRIORITY_MEDIUM, "Setting up Receive Notify");
status = nx_tcp_socket_receive_notify(&tcpSocket, tcpDataReceived);
UPEND_CHECK(status, "Receive Notify");
/* Loop to create and establish server connections. */
while(1)
{
status = nx_tcp_client_socket_connect(&tcpSocket, HOST_IP_ADDRESS, HOST_SOCKET, NX_WAIT_FOREVER);
// status = nx_tcp_client_socket_connect(&tcpSocket, HOST_IP_ADDRESS, HOST_SOCKET, 1000);
UPEND_CHECK(status, "Socket Connect");
/* Allocate a packet. */
LOG(MESSAGE_PRIORITY_MEDIUM,"Allocating Tx Packet");
status = nx_packet_allocate(&pool_0, &txPacketPtr, NX_TCP_PACKET, NX_WAIT_FOREVER);
/* Check for error. */
UPEND_CHECK(status, "Allocate TX Packet");
/* Place "Hello_and_Goodbye" in the packet. */
LOG(MESSAGE_PRIORITY_MEDIUM,"Filling packet with data");
UCHAR fakeData[13] = {13,0xfB,0xff,0xff,0x07,0,0,1,123,00,29,01,15};
nx_packet_data_append(txPacketPtr, fakeData, 13, &pool_0, NX_WAIT_FOREVER);
LOG(MESSAGE_PRIORITY_MEDIUM,"Sending packet to host");
status = nx_tcp_socket_send(&tcpSocket, txPacketPtr, NX_WAIT_FOREVER);
/* Determine if the status is valid. */
UPEND_CHECK(status, "Send Packet");
// we need to release the packet if there was an error. If success, the send routine release it.
if(status != NX_SUCCESS){
nx_packet_release(txPacketPtr);
}
status = nx_tcp_socket_disconnect(&tcpSocket, 400);
UPEND_CHECK(status, "Socket Disconnect");
tx_thread_sleep(1000);
}