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.

RTOS/BEAGLEBK: UDP Echo Server/Client Example for Beagleboneblack

Part Number: BEAGLEBK

Tool/software: TI-RTOS

Hi,

Here is the system setup that I am using:

Platform: Beaglebone Black

EDMA3 Low Level Driver 2.12.5

NDK 3.40.1.01

SYS/BIOS 6.73.1.01

am335x PDK 1.0.13

Base Source: NIMU_BasicExample_bbbAM335x_armExampleProject

I want to use Sockets API to send/receive data on my host computer. First I tried with making my board as client and host computer as server. The code of the client looks as follows. I start the server at my host computer and start debugging the application. The application exits with Data Abort exception when I try to connect to the host computer.

void client()
{
        SOCKET s;
        int status;
        char data[] = "Hello";
        struct sockaddr_in cli_addr;
        s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
        if (s <0)
        {
            UART_printf("Socket not created: %d\n", fdError());
        }

        memset(&cli_addr, 0, sizeof(cli_addr));
        cli_addr.sin_family = AF_INET;
        cli_addr.sin_addr.s_addr = inet_addr("192.168.1.10");
        cli_addr.sin_port = 17225;

        int err = NDK_connect(s, (struct sockaddr *)&cli_addr, sizeof(cli_addr));
        if(err<0)
        {
            UART_printf("%x\n",fdError());
        }
        while(1)
        {
            err = NDK_send(s, data, sizeof(data), 0);
            if(err<0)
            {
                UART_printf("%x\n",fdError());
            }
        }
}

Then, I try to make my board as server and host computer as client. The code for the server app on board looks as follows. I launch the application on board and connect the host computer using telnet. The host computer connects successfully. However, I am not able to receive any data on the board (NDK_recvfrom)and I get the fdError as 16 (DEVICE_BUSY in serrno.h). I am not able to understand this strange behavior.

SOCKET s;
    struct sockaddr_in local_addr, cli_addr;
    char buffer[256];
    s = NDK_socket(AF_INET, SOCK_STREAM, 0);
        if (s == INVALID_SOCKET)
        {
            UART_printf("%x\n", fdError());
        }
/*I am adding a comment 3*/
    memset(&local_addr,0,sizeof(local_addr));
    local_addr.sin_family = AF_INET;
    local_addr.sin_addr.s_addr = INADDR_ANY;
    local_addr.sin_port = 17225;

    int err = NDK_bind(s,(struct sockaddr *)&local_addr, sizeof(local_addr));
    if(err<0)
    {
        UART_printf("%d\n", fdError());
    }
    int size = sizeof(cli_addr);

    err = NDK_listen(s, 10);
    UART_printf("%d\n", err);
    if(err<0)
        {
            UART_printf("%d\n", fdError());
        }
    SOCKET computer = NDK_accept(s,(struct sockaddr *)&cli_addr, &size);
    if(computer ==INVALID_SOCKET)
    {
        UART_printf("Error: %x\n", fdError());
    }
    while(1)
    {
        int bytes = NDK_recvfrom(s, buffer,sizeof(buffer),0,(struct sockaddr *)&cli_addr, &size);
        if(bytes<0)
        {
            UART_printf("Error: %x\n", fdError());
        }
        if (bytes>0)
        {
            int bytesSent = sendto(s, buffer, bytes, 0,
                                        (struct sockaddr *)&cli_addr, sizeof(cli_addr));
        }
    }

I would request TI to please help me with following:

1. Is there any TCP/UDP Echo example for AM335x or Beaglebone Black? (I know there are examples from TIVA C and I followed the same procedure, what is in there but I get exceptions)

2. It seems to me that something is wrong with the configuration of the Ethernet. Do you think above errors are because of incorrect configuration?

Regards

Vishav