Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

First time using lwIP

Hello, I´ve started using lwIP this week. I tried the Webserver example and it worked fine (I can access the webpage from my browser =).

Well... I read the code many times and couldn´t understand how it works. I didn´t find any good documentation about it either. I just want to create a simple app server to send and receive messages (from a telnet client, for example). I didn't find any API like "send" and "recv" of Socket's...

Do someone have any example that could help me?

Until now, my code is just it:

main()

{

alt_avalon_lan91c111_if* dev_list_ptr = (alt_avalon_lan91c111_if*)alt_ethernet_device_list.next;

lwip_init();

IP4_ADDR(&ipaddr, 192, 168, 0, 100);

IP4_ADDR(&netmask, 255, 255, 255, 0);

IP4_ADDR(&gw, 192, 168, 0, 1);

netif_add(&netif, &ipaddr, &netmask, &gw,

(void*)dev_list_ptr,

lan91c111if_init,

ip_input);

netif_set_default(&netif);

pcb = tcp_new();

tcp_bind(pcb, IP_ADDR_ANY, 80);

pcb = tcp_listen(pcb);

}

Then I don't know how to go on (I don´t even know if I´m in the right way...)

Can anybody help me?

Thanks

4 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks for the pdf.

    I can start the server now, but I still can't send and receive messages.

    How do I use the tcp_accept anyway?

    I tried something like

    pcb = tcp_new();

    tcp_bind(pcb, IP_ADDR_ANY, 80);

    pcb = tcp_listen(pcb);

    tcp_accept(pcb, ERR_OK);

    while(1)

    {

    printf("\nI will send");

    getchar();

    tcp_write(pcb, "lalala", sizeof("lalala"), 0);

    }

    Well.... then my client can connect, but it won´t receive anything.

    If I do something like:

    tcp_accept(pcb, envia);

    and create the function "envia" like this:

    static err_t

    envia(void *arg, struct tcp_pcb *pcb, err_t err)

    {

    int i;

    for(i = 0; i < 5; i++)

    {

    printf("\nVou enviar");

    getchar();

    tcp_write(pcb, "lalala", sizeof("lalala"), 0);

    }

    return ERR_OK;

    }

    It will send the "lalala" five times when it reaches the "return".

    But I want to use the tcp_write inside the main

    How do I do that?

    Thanks
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    It looks like you&#39;re trying to LWIP&#39;s "raw" and/or stand alone API. This is a _callback_-based API. You need to, at a bare minimum, read through the raw_api.txt file.

    In addition, it makes sense to take a look at the TCP echo server, included with the distribution on this website, and use it as a basis for starting your own application. Once you have it working, you&#39;ll have much more luck stripping out what you don&#39;t feel you need.

    Cheers,

    - slacker
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hello,

    I read that document and I also have the webserver working here.

    But it still use that open-read-write-close idea, right?

    I need to write a code to talk to a client. I mean... I can send messages to the client inside the function called on "tcp_accept", but just that. I can&#39;t keep sending (or receiving) messages in main().

    How can I do that?