Gavin <[email protected]> wrote:

> I make the below test code to verify TCP sending, it works, but something is
> unexpected.
> 
> const char *helloworld = "hello world\n";
> const char *helloworld1 = "hello world1\n";
> 
> err_t LAN_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
> {
>        tcp_write(pcb, helloworld, 12, 0);
>        return ERR_OK;
> }
> 
> err_t LAN_sent1(void *arg, struct tcp_pcb *pcb, u16_t len)
> {
>        tcp_write(g_pcb, helloworld1, 13, 0);
>        return ERR_OK;
> }
> 
> int main()
> {
> ...
>        if ((g_pcb = tcp_new()) == NULL)
>        {
>                mem_free(state);
>                return ERR_MEM;
>        }
> 
>        tcp_arg(g_pcb, state);
>        tcp_err(g_pcb, LAN_err);
>        tcp_recv(g_pcb, LAN_recv);
>        tcp_sent(g_pcb, NULL);
> 
>        err = tcp_connect(g_pcb, &ipaddr, SERVER_PORT, LAN_sent);
>        if (err != ERR_OK)
>        {
>                mem_free(state);
>                tcp_abort(g_pcb);
>        }
> 
>        tcp_sent(g_pcb, LAN_sent1);
> ...
> }
> 
> And I get the such result on the server;
> 
> hello world
> hello world1
> hello world1
> hello world1
> hello world1
> ...
> 
> I expect that "hello world1" is just printed once like "hello world".

tcp_sent() is your ACK-callback, so to say.  When you send something,
remote acks its reception to you, so your tcp_sent callback is called,
which sends something, which remote acks, ... etc, etc.

So what you see is expected, given your setup.

-uwe


_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to