lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] How to control TCP sending by raw API?


From: Noam weissman
Subject: Re: [lwip-users] How to control TCP sending by raw API?
Date: Thu, 11 Sep 2014 00:58:12 +0300

Hi,

As a continuation to the reply written by -uwe if it is not clear let me 
elaborate.


You have a few callback function that can be used in a connection
based server using RAW mode.

You have the tcp_sent, tcp_poll and the tcp_err callback's

You use these as follows:

tcp_sent is called after a packet has been transmitted and the TCP stack 
received the ACK. The TCP stack will free any pcb's or any other memory 
allocated inside the stack and call your own callback.

This is used to send data in an ordered meaner and to control the flow.
in you case you send the helloworld1  packet on every call, like an endless 
loop. 

tcp_poll is used for house keeping:
tcp connection timeout, send more data that is left in a buffer or some other
tasks needed.

tcp_err is used to handle disconnection or some other system errors


Take a look at the simple echo server in the contribution directory to get a 
better
understanding. I think the older echo server code in LwIP version 1.32 is 
simpler.

BR,
Noam.


-----Original Message-----
From: address@hidden on behalf of Valery Ushakov
Sent: Wed 9/10/2014 10:02 PM
To: address@hidden
Subject: Re: [lwip-users] How to control TCP sending by raw API?
 
Gavin <address@hidden> 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
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users

 
 
************************************************************************************
This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals & computer 
viruses.
************************************************************************************







************************************************************************************
This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals & computer 
viruses.
************************************************************************************



<<winmail.dat>>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]