[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] How to control TCP sending by raw API?
From: |
Valery Ushakov |
Subject: |
Re: [lwip-users] How to control TCP sending by raw API? |
Date: |
Wed, 10 Sep 2014 19:02:07 +0000 (UTC) |
User-agent: |
tin/2.0.1-20111224 ("Achenvoir") (UNIX) (NetBSD/6.1_RC1 (macppc)) |
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