This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3100MODBOOST: Consecutive TCP write and read

Part Number: CC3100MODBOOST
Other Parts Discussed in Thread: CC3100

Hello,

I am able to open, connect, send and receive and then close tcp just fine. But I noticed that, whenever I do a consecutive write and read, it doesn't.. Even just a consecutive send won't work. The display on my packet sender program would just show one packet transmitted. I would have to close the socket first and then connect and then send and receive. Is there a way to keep the socket open and continuously send and receive until I decide to stop and close? What I am doing is sending commands to serial terminal UART that's why you see code divided by if statements. 0 - open and connect, 1- close, 2 - send and receive.

When I enter 0, the device connects and opens successfully. Then I enter 2. It sends and receives data ok. But when I enter 2 the second time, I don't get an error yet but the packet is not sent. I enter 2 the third time, no error on sl_Send but sl_Receive gives me an error. Thing is, I am not able to send a receive consecutively. I need to enter 1 to close and then repeat the process. Am I missing anything?

Thanks a lot

AJ
 
                if(UART0RxBytes[0] == '0')//Open TCP socket
                {
                    WriteUART0("\n\n\rOpen and Connect to Socket");
                    CC3100StatFlags.ErrorFlag = OpenTCPSocket();
                    if(CC3100StatFlags.ErrorFlag == CC3100_NO_ERROR)
                    {
                        WriteUART0("\n\rSocket Open");
                    }//end if(CC3100StatFlags.ErrorFlag == CC3100_NO_ERROR)
                    else
                    {
                        WriteUART0("\n\rSocket Open and Connect ERROR");
                    } //end else
                    PrintCC3100Error();
                }//end if(UART0RxBytes[0] == '0')//Open TCP socket
                /***********************************************/
                else if(UART0RxBytes[0] == '1')//Close TCP socket
                {
                    WriteUART0("\n\n\rClose TCP Socket");
                    CC3100StatFlags.ErrorFlag = CloseTCPSocket();
                    if(CC3100StatFlags.ErrorFlag == CC3100_NO_ERROR)
                    {
                        WriteUART0("\n\rSocket Close");
                    }//end if(CC3100StatFlags.ErrorFlag == CC3100_NO_ERROR)
                    else
                    {
                        WriteUART0("\n\rSocket Close ERROR");
                    } //end else
                    PrintCC3100Error();
                }//end else if(UART0RxBytes[0] == '1')//Close TCP socket
                /***********************************************/
                else if(UART0RxBytes[0] == '2')//Send to TCP
                {
                    WriteUART0("\n\n\rSend to TCP Socket");
                    CC3100StatFlags.ErrorFlag = SendToTCPSocket(SockID, "HELLO", 5, 0);
                    if(CC3100StatFlags.ErrorFlag == CC3100_NO_ERROR)
                    {
                        WriteUART0("\n\rSend to TCP OK");
                        CC3100StatFlags.ErrorFlag = RecvFromTCPSocket(SockID, integerArray, 5, 0);
                        WriteUART0("\n\r");
                        WriteUART0(integerArray);
                    }//end if(CC3100StatFlags.ErrorFlag == CC3100_NO_ERROR)
                    else
                    {
                        WriteUART0("\n\rSend to TCP ERROR");
                    } //end else
                    PrintCC3100Error();
                }//end else if(UART0RxBytes[0] == '2')//Send to TCP
  • I meant "But I noticed that, whenever I do a consecutive send and receive, it doesn't work..
  • I forgot to add, here are the implementation of the functions I used in my previous post
    int32_t GetHostIP(int8_t *hostName)
    {
        _i32 retVal = 0;
        if(CC3100StatFlags.ConnectStatus == CC3100_CONNECTED)
        {
            retVal = sl_NetAppDnsGetHostByName(hostName, strlen((char *)hostName), &CC3100IPAdd.HostIP, SL_AF_INET);
            if (retVal < 0)
            {
                return CC3100_WLAN_EVENT_ERROR;
            }
            return CC3100_NO_ERROR;
        }//end if(CC3100StatFlags.ConnectStatus == CC3100_CONNECTED)
        else
        {
            return CC3100_WLAN_EVENT_ERROR;
        }
    }//end int32_t GetHostIP(int8_t *hostName)
    /***********************************************/
    int32_t OpenTCPSocket(void)
    {
        int32_t retVal = 0;
        if(CC3100StatFlags.ConnectStatus == CC3100_CONNECTED && CC3100StatFlags.TCPStatus == CC3100_TCP_CLOSE)
        {
            retVal = GetHostIP((int8_t *)HOST);
            if (retVal < 0)
            {
                return CC3100_TCP_ERROR;
            }//end
            else
            {
                ServerAddr.sin_family = SL_AF_INET;
                ServerAddr.sin_port = sl_Htons((uint16_t)PORT_NUM);
                ServerAddr.sin_addr.s_addr = sl_Htonl((uint32_t)CC3100IPAdd.HostIP);
                LocalAddr.sin_family = SL_AF_INET;
                LocalAddr.sin_port = sl_Htons((uint16_t)PORT_NUM);
                LocalAddr.sin_addr.s_addr = sl_Htonl((uint32_t)CC3100IPAdd.StationIP);
                AddrSize = sizeof(SlSockAddrIn_t);
                SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
                if(SockID < 0)
                {
                    return CC3100_TCP_ERROR;
                }//end if(SockID < 0)
                else
                {
                    CC3100StatFlags.TCPStatus = CC3100_TCP_OPEN;
                    retVal = sl_Connect(SockID, (SlSockAddr_t *)&ServerAddr, AddrSize);
                    if(retVal < 0)
                    {
                        return CC3100_TCP_ERROR;
                    }//end if(retVal < 0)
                    else
                    {
                        return CC3100_NO_ERROR;
                    }//end else
                }//end else
            }//end else
        }//end if(CC3100StatFlags.ConnectStatus == CC3100_CONNECTED && CC3100StatFlags.TCPStatus == CC3100_TCP_CLOSE)
        else
        {
            return CC3100_TCP_ERROR;
        }
    }//end int32_t OpenTCPSocket(void)
    /***********************************************/
    int32_t CloseTCPSocket(void)
    {
        int32_t retVal = 0;
        if(CC3100StatFlags.ConnectStatus == CC3100_CONNECTED && CC3100StatFlags.TCPStatus == CC3100_TCP_OPEN)
        {
            retVal = sl_Close(SockID);
            if (retVal < 0)
            {
                return CC3100_TCP_ERROR;
            }//end
            else
            {
                CC3100StatFlags.TCPStatus = CC3100_TCP_CLOSE;
                return CC3100_NO_ERROR;
            }//end else
        }//end if(CC3100StatFlags.ConnectStatus == CC3100_CONNECTED && CC3100StatFlags.TCPStatus == CC3100_TCP_CLOSE)
        else
        {
            return CC3100_TCP_ERROR;
        }
    }//end int32_t CloseTCPSocket(void)
    /***********************************************/
    int32_t SendToTCPSocket(int16_t sockID, const void *message, int16_t msgLength, int16_t flags)
    {
        int32_t retVal = 0;
        if(CC3100StatFlags.ErrorFlag != CC3100_TCP_ERROR  && CC3100StatFlags.TCPStatus == CC3100_TCP_OPEN)
        {
            retVal = sl_Send(sockID, message, msgLength, flags);
            if (retVal < 0)
            {
                return CC3100_TCP_ERROR;
            }//end
            else
            {
                return CC3100_NO_ERROR;
            }//end else
        }//end if(CC3100StatFlags.ErrorFlag != CC3100_TCP_ERROR  && CC3100StatFlags.TCPStatus == CC3100_TCP_OPEN)
        else
        {
            return CC3100_TCP_ERROR;
        }//end else
    }//end int32_t SendToTCPSocket(int16_t sockID, const void *message, int16_t msgLength, int16_t flags)
    /***********************************************/
    int32_t RecvFromTCPSocket(int16_t sockID, void *message, int16_t msgLength, int16_t flags)
    {
        int32_t retVal = 0;
        if(CC3100StatFlags.ErrorFlag != CC3100_TCP_ERROR  && CC3100StatFlags.TCPStatus == CC3100_TCP_OPEN)
        {
            retVal = sl_Recv(sockID, message, msgLength, flags);
            if (retVal < 0)
            {
                return CC3100_TCP_ERROR;
            }//end
            else
            {
                return CC3100_NO_ERROR;
            }//end else
        }//end if(CC3100StatFlags.ErrorFlag != CC3100_TCP_ERROR  && CC3100StatFlags.TCPStatus == CC3100_TCP_OPEN)
        else
        {
            return CC3100_TCP_ERROR;
        }//end else
    }//end int32_t RecvFromTCPSocket(int16_t sockID, void *message, int16_t msgLength, int16_t flags)
  • I finally figured it out. The Packet Sender program when acts as a TCP server closes the socket after the first transaction. I used another program called Socket Test and it works. Just a note, when Socket Test sends a packet, it adds 0a 0d to the message.
  • Hi AJ_ee,

    Thanks for letting us know how you resolved your issue. We really appreciate posters providing the fix to their issue, so that others who run into the same issue will be able to learn from your debug effort.

    Regards,
    Michael