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.

UDP Socket Sendto Error .

Other Parts Discussed in Thread: EK-TM4C1294XL, SYSBIOS

TI-RTOS for TivaC 2.10.1.38

XDCtools 3.30.4.52

2 interfaces EK-TM4C1294XL

hi,
One of the interface are as UDP socket server (example UDPecho) and works well with udpSendReceive.exe.
The other interface is as UDP client socket to communicate with the UDP server (UDPecho), but gives an error in the function:

bytes_sent = sendto (client, buffer, buffSize, 0, (struct sockaddr *) & servAddr, sizeof (servAddr));

That is the function always returns -1.

The client code for the following:

#define NDK_UDPPORT 1025
#define SERVER_IP "192.168.1.133"
#define SLEEPTIME 1000
#define Sleep Task_sleep

Void echoFxnClient(UArg arg0, UArg arg1)
{
    int i;
    SOCKET client;
    int status = 0;
    int sleepTime = SLEEPTIME;
    struct sockaddr_in bindAddr;
    struct sockaddr_in servAddr;
    int bytes_read, bytes_sent;
    char *buffer;
    struct sockaddr_in fromAddr;
    int fromAddrLen = sizeof(fromAddr);
    fd_set readfds;
    struct timeval timeout;
    int count = 0;
    int id;
    time_t start;
    unsigned int buffSize  = MAXBUF;

    fdOpenSession(TaskSelf());

    buffer = malloc(buffSize);
    if (!buffer) {
        goto QUIT;
    }
    memset(buffer, 0, buffSize);

    /* initialize destination address */
    memset(&servAddr, 0, sizeof(servAddr));
    servAddr.sin_family = AF_INET;
    inet_aton(SERVER_IP, &servAddr.sin_addr);
    servAddr.sin_port = htons(SERVER_UDPPORT);

    // # # # # 1) 
    client = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

    memset(&bindAddr, 0, sizeof(bindAddr));
    bzero((char *)&bindAddr,sizeof(bindAddr));
    bindAddr.sin_family = AF_INET;
    bindAddr.sin_addr.s_addr =  htonl(INADDR_ANY);
    bindAddr.sin_port = htons(NDK_UDPPORT);

    // # # # # 2) 
    if (bind(client, (struct sockaddr *)&bindAddr, sizeof(bindAddr)) < 0) {
        goto QUIT;
    }

    // # # # # 3) 
    /* loop */
    i = 0;
    while (1) {
        buffer[0] = (char)(++i);
        buffer[buffSize - 1] = (char)~i;

        /* send the data */
        bytes_sent = sendto(client, buffer, buffSize, 0, (struct sockaddr *)&servAddr, sizeof(servAddr));

        if (bytes_sent < 0 || bytes_sent != buffSize) {	//    #########  ERROR ############
        	GPIO_write(Board_LED1, Board_LED_ON);   // <--
            goto QUIT;
        }

        // # # # # 3B) 
        bytes_read = recvfrom(client, buffer, buffSize, MSG_WAITALL,
               (struct sockaddr *)&fromAddr, &fromAddrLen);

        if (bytes_read < 0 || bytes_read != buffSize) {	// Se recebe a mensagem
        	GPIO_write(Board_LED1, Board_LED_OFF);
            goto QUIT;
        }
        else {
        }

        count++;
        if (count % 1000 == 0) {
        }

        /* Sleep specified time */
        Sleep(sleepTime / 1000);

        if ((buffer[0] != (char)i) || (buffer[buffSize - 1] != (char)~i)) {
        }
    }

QUIT:
	// # # # # 5) 
    if (client) {
        fdClose(client);
    }
    free(buffer);
    fdCloseSession(TaskSelf());
}

My doubt is because sendto returns -1?

 

Regards

Aquino