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.

Tm4c1294 connection with C server without using RTOS.



Hi,

I want to connect my TM4C1294 device to the C server without using RTOS and I have gone through the tivaware examples but unable to use it as client program.

Kindly help!

Regards,

SS.

  • Hello Shaheen,

    Can you explain what you mean by C server? What peripheral are you trying to use? If using Ethernet, what protocol do you want to use?

    Thanks,
    Sai
  • Hello Sai,

    Thanks for replying.

    I mean normal C server which is listening to a port in one PC and I want to connect to this server with Tm4c1294 board through Ethernet using LWIP stack.

    I have gone through :

    I am using this code:

    void my_client_init(void)

    {

      struct tcp_pcb *pcb;

      struct ip_addr dest;

      err_t ret_val;

      IP4_ADDR(&dest, 192, 168, 1, 15);

      pcb = tcp_new();

      tcp_bind(pcb, IP_ADDR_ANY, 8889);

      ret_val = tcp_connect(pcb, &dest, 8888, client_connected);

      if (ret_val != ERR_OK)

      UARTprintf("\tcp_connect(): Errors on return value, returned value is %d\n", ret_val);

    }

    but its not working.

    Regards,

    SS

  • Hello Shaheen,

    I don't understand what a "C Server" is. Does it mean that the server is written in C language?

    Assuming that it is a server written in C, you will need to know what protocol the server is using - TCP and UDP being the most popular. In your code you are opening a TCP socket. Make sure that the server is also using TCP.

    Next you need to know what port the server is listening on. This is the port that the client should be trying to connect on. In your code you are using two different ports - 8889(to bind) and 8888 (to connect). Same port number should be used to bind and connect. You need to find out which one the server expects a connection on.

    The link you provided already gives details on how to open a socket as a server and client. If the TM4C device is going to connect as a client, then follow the steps under "Active connection".

    Thanks,
    Sai
  • Hello Sai,

    Thanks for replying.

    Yes the server is written in C language.

    The server is using TCP and listening to the 8888 port.

    Have changed the code as you said and followed the 'Active Connection' part . The code is given below:

    static void
    client_close(struct tcp_pcb *pcb)
    {
    tcp_arg(pcb, NULL);
    tcp_sent(pcb, NULL);
    tcp_close(pcb);
    }
    static err_t client_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
    {
    LWIP_UNUSED_ARG(arg);

    UARTprintf("\nclient_sent(): Number of bytes ACK'ed is %d", len);

    client_close(pcb);

    return ERR_OK;
    }

    static err_t client_connected(void *arg, struct tcp_pcb *pcb, err_t err)
    {
    char *string = "Hello!";
    LWIP_UNUSED_ARG(arg);

    if (err != ERR_OK)
    {
    UARTprintf("\nclient_connected(): err argument not set to ERR_OK, but is value is %d\n", err);
    }
    else
    {
    tcp_sent(pcb, client_sent);
    tcp_write(pcb, string, sizeof(string), 0);
    }

    return err;
    }

    void my_client_init(void)
    {
    struct tcp_pcb *pcb;
    struct ip_addr dest;
    err_t ret_val;
    IP4_ADDR(&dest, 192, 168, 1, 14);
    pcb = tcp_new();
    tcp_bind(pcb, IP_ADDR_ANY, 1025);
    tcp_arg(pcb, NULL);
    ret_val = tcp_connect(pcb, &dest, 1025, client_connected);
    if(ret_val != ERR_OK)
    {
    UARTprintf("\tcp_connect(): Errors on return value, returned value is %d\n", ret_val);
    }
    else
    {
    UARTprintf("\tcp_notconnect(): Errors on return value, returned value is %d\n", ret_val);
    }
    }

    The tcp_connect() function is returning -4 as error which implies :

    /* Don't even try to send a SYN packet if we have no route
    since that will fail. */
    return ERR_RTE;

    Kindly help.

    Regards,
    SS