lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] netconn_x API, Connecting a TCP client fails


From: address@hidden
Subject: Re: [lwip-users] netconn_x API, Connecting a TCP client fails
Date: Tue, 09 Mar 2010 16:18:24 +0100
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; de; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3

Sägesser Walter wrote:
This code actually works, if the server does not close its client it got at connect time.
But that's not what I really want. The client task may have nothing to do for a long time. But when there's something to do, it should open a connection and send whatever is due and then close the connection again.
I thought, if I remove the 'if (!xIni)' in the code above and uncomment the 'netconn_delete', it should work exactly the same (the server would have to close its client and wait for a new connection).
 
But it doesn't. The 'netconn_bind' returns with -11 (Address used), which I don't understand because I delete the netconn and all the resources are released, aren't they? Certainly there must be a way to properly close down the connection and reopen it. Can anyone give me a hint? Thanks in advance!
The problem you are seeing here is that TCP does not allow binding to a port twice. And although you called netconn_delete, the old port is still floating around (in TIME_WAIT state) for some minutes (this is a kind of safety implementation in TCP). You'd normally have three options here:
- don't bind the netconn before connecting: your netconn will get an arbitrary local port assigned (your server has to cope with remote_port not being 9000 then, but that's normally not a problem)
- use SO_REUSEADDR which allows binding if the other pcb is in TIME_WAIT
- wait for some minutes before reconnecting

Since SO_REUSEADDR is still not fully implemented, you can currently not use it, I guess, so you have only 2 options left.

Simon

reply via email to

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