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.

TM4C1294NCPDT: Simple UDP socket programming for the Tiva microcontrollers

Part Number: TM4C1294NCPDT

hi there,

Now I did experiment with one thing and that is I copied the udpecho code from the TI resource explorer and build it and ran successfully.

But this is the server code actually and I want to implement the udp client code , so keeping this in mind I did the following changes to the echoFxn() in the udpEcho.c file :

Void echoFxn(UArg arg0, UArg arg1)
{
    int                bytesRcvd;
    int                bytesSent;
    int                status;
    int                client;
    fd_set             readSet;
    struct sockaddr_in ServerAddr;
    socklen_t          addrlen;
    char               buffer[UDPPACKETSIZE];

    char* hostname = "192.168.80.171";
    int portno = 1000;

    client = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if (client == -1) {
        System_printf("Error: socket not created.\n");
        goto shutdown;
    }

    memset(&ServerAddr, 0, sizeof(struct sockaddr_in));
    ServerAddr.sin_family = AF_INET;
    //ServerAddr.sin_addr.s_addr = inet_addr(hostname);
    if(inet_aton(hostname,&ServerAddr.sin_addr) == 0){
        System_abort("Error in adding the Server Ip\n");
    }
    ServerAddr.sin_port = htons(portno);

    for(;;){

        strcpy(buffer,"Hello Piyush");

        addrlen = sizeof(struct sockaddr_in);
        bytesSent = sendto(client, buffer, strlen("Hello Piyush"), 0,
                                (struct sockaddr *)&ServerAddr, addrlen);

        if (bytesSent < 0) {
            System_printf("Error: sendto failed.\n");
            goto shutdown;
        }

        //System_printf("Size of two structures:%d\t%d",sizeof(struct sockaddr),sizeof(struct sockaddr_in));
        //System_flush();

        /*
         *  readSet and addrlen are value-result arguments, which must be reset
         *  in between each select() and recvfrom() call
         */

#if 1
        FD_ZERO(&readSet);
        FD_SET(client, &readSet);
        addrlen = sizeof(ServerAddr);

        /* Wait forever for the reply */
        status = select(client, &readSet, NULL, NULL, NULL);
        if (status > 0) {
            if (FD_ISSET(client, &readSet)) {
                bytesRcvd = recvfrom(client, buffer, UDPPACKETSIZE, 0,
                        (struct sockaddr *)&ServerAddr, &addrlen);

                if (bytesRcvd > 0) {

                }
             }
         }
#endif

        Task_sleep(2000);

    }

shutdown:
    if (client > 0) {
        close(client);
    }
}

The program is build successfully and running , but the problem is that I am able to see the send packet from UDP client to my PC in the wireshark but the receive packet is not seen here and there are list of black messages in the wireshark stating that :

33844 163.335566   192.168.80.154      192.168.80.171         ICMP             70               Destination unreachable (Port unreachable)

 So I know that I am missing one small thing , but not to locate that point exactly what is that , so I want your help.

regards