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.

LAUNCHCC3220MODASF: Implementing a client socket connection from on a cc3220

Part Number: LAUNCHCC3220MODASF
Other Parts Discussed in Thread: CC3200

Implementing a client socket connection

I have found an example, but I don't think I am putting the Server IP (Gateway) address ( C0A83101 or 192.168.49.1 ) in the sAddr structure correctly.

processors.wiki.ti.com/.../CC32xx_TCP_Socket_Application_0.5.2

The error that is returned is a -111, connection refused, as seen from my console below

[NETAPP EVENT] IP set to: IPv4=192.168.49.113 , Gateway=192.168.49.1
user:
[p2pstart] : P2p Connected, Starting Socket connection

[p2pstart] : Client Connection sl_Socket()

[p2pstart] : Client Connection sl_Connect()

[p2pstart] : C0A83101
[p2pstart] : sl_Connect()[line:1734, error:-111] Socket error, please refer "SOCKET ERRORS CODES" section in errors.h

Here is my implementation of the client socket connect

    //  Open a socket with standard parameters
    UART_PRINT("\n\r[p2pstart] : Client Connection sl_Socket()\n\r");
    newsock = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
    if( newsock < 0 )
    {
    // error
    UART_PRINT("[p2pstart] : sl_Socket()[line:%d, error:%d] %s\n\r", __LINE__, status, SL_SOCKET_ERROR);
    return -1;
    }

    //Connect to the server IP and port number
    UART_PRINT("\n\r[p2pstart] : Client Connection sl_Connect() \n\r");
    UART_PRINT("\n\r[p2pstart] : %X \n\r", sAddr.in4.sin_addr.s_addr);
    status = sl_Connect(newsock, csa, addrSize );
    if( status < 0 )
    {
    // error
    UART_PRINT("[p2pstart] : sl_Connect()[line:%d, error:%d] %s\n\r", __LINE__, status, SL_SOCKET_ERROR);
    sl_Close(newsock);
    return -1;
    }

Here is my attempt to write the IP address to the sAddr structure that is pointed to by the csa pointer

/* filling the TCP server socket address */
        sAddr.in4.sin_family = SL_AF_INET;

        /* Set the server's port: We'll receive connection requests on this port */
        sAddr.in4.sin_port = sl_Htons((unsigned short)portNumber);      // 5001
//        sAddr.in4.sin_addr.s_addr = SL_INADDR_ANY;
        sAddr.in4.sin_addr.s_addr = app_CB.CON_CB.GatewayIP;      //C0A83101 or 192.168.49.1

        sa = (SlSockAddr_t*)&sAddr.in4;
        csa = (SlSockAddr_t*)&sAddr.in4;
        addrSize = sizeof(SlSockAddrIn_t);

 

  • Hi,

    Your connection code is not correct (addr parameter in sl_Connect in wrong). Please see 5.5.1.1 at www.ti.com/.../swru455

    If I may a advice. In case of that you working with CC3220 device, it is not a best approach follow Wiki pages for previous generation (CC3200), especially with pre-release SDK versions.

    Jan
  • I'm studying swru455, but see no difference in what i did and the swru455 manual implementation on page 84.

    Addr.sin_family= SL_AF_INET;
    Addr.sin_port= sl_Htons(5001);
    Addr.sin_addr.s_addr= sl_Htonl(SL_IPV4_VAL(192,168,1,31));
    Sd = sl_Socket(SL_AF_INET,SL_SOCK_STREAM,0);
    if( 0 > Sd )
    {
    // error
    }
    Status= sl_Connect(Sd,( SlSockAddr_t*)&Addr,sizeof(SlSockAddrIn_t));
    if( Status)
    {
    // error
    }
  • Hi,

    OK, my bad. It really confused me how you have declared sAddr.

    Are you sure that you connection is not blocked at other side 192.168.49.1 and server is running there? Maybe you can check that by Wireshark. Error code -111 mainly shown when connection is blocked at other side.

    Jan
  • Hi Gary, see the Network Terminal example in the CC3220 SDK

    sAddr.in4.sin_addr.s_addr = sl_Htonl((unsigned int)ipAddress.ipv4);

    don't forget the htonl

    -Aaron