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.

CC3000 server configuration

What steps should I take to convert the basic wifi application from a client to a server based TCP connection?  

It looks like I should alter the receivedata command to use the listen() and accept() functions.  These would replace the existing recv() function.  I also figure that the senddata command does not need to be altered for server operation.  Am I headed in the right direction?

Thanks,
Jackson

  • Hi Jackson,

    You should follow the below sequence to setup a TCP server:

    1) Create a TCP socket. This will return a socket descriptor listenFd.

    2) Assign the port number on which you want your server to listen on. Assign this to the sockaddr structure variable, and also set the IP address octets to 0x00. After this, using the listenFd perform a bind and then call listen.

    3) Then call accept. This will return the client's socket descriptor say clientFd when the TCP client connects to it.

    4) Using the clientFd call recv. This will receive the data sent by the client. Similarly, to send the data to the client you can use the API send.

    Thanks & Regards,
    Raghavendra

  • Is there an event triggered when data is received?  It seems that the recv() function will halt the MCU while waiting for a reply.  I'd like to receive TCP data as an interrupt.

    Thanks,

    Jackson

  • Hi Jackson,

    You can use non-blocking receive for this purpose. On the clientFd you can call the setsockopt for the following opt name 'SOCKOPT_RECV_NONBLOCK'. This will make the sequence not to block at the recv API.

    Thanks & Regards,
    Raghavendra

  • Thanks again Raghavendra.  The steps for initiating a server were spot on.  I will have to post a helpful server example that I used when I get home.  But overall, I was able to use those steps to set up the server successfully last night.  I did find one potential bug you might be interested in:

    The Tivaware basic_wifi example  creates the TCP socket with a SOCK_DGRAM.  I had to change this to SOCK_STREAM to get my server to work.  

    Also thanks for the note on setting up a non-blocking socket.  I'll try that out next.  

  • Hi,

    While entering the port details into the sockaddr structure did your just enter the port number into the sockaddr.sa_data? For example I want to enter port number 9876 into the structure. If I perfrom the statement

    tSocketAddr.sa_data[0] = 98;
    tSocketAddr.sa_data[1] = 76; 

    will this set the port number successfully?

    Thanks and regards,

    Raven

  • Raven Powerful said:

    will this set the port number successfully?

    No, the binary representation will be incorrect. I suggest using the sockaddr_in structure for convience as per the example I added to your other post: http://e2e.ti.com/support/wireless_connectivity/f/851/t/337487.aspx

  • Hi,

    What if I enter the Port nmber in hex in the structure.

    hostAddr.sa_family = AF_INET;
    hostAddr.sa_data[0] = 0x26;
    hostAddr.sa_data[1] = 0x94;

    // all 0 IP address
    memset (&hostAddr.sa_data[2], 0, 4);

    bind(ulSocket, &hostAddr, sizeof(sockaddr));

    This should  successfully create a UDP server socket shouldn't it?

    Regards,

    Raven