[Top][All Lists]

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

[lwip-users] Re: About my problem...

From: Atte Kojo
Subject: [lwip-users] Re: About my problem...
Date: Fri, 10 Mar 2006 13:45:43 +0200
User-agent: KMail/1.9.1

On Friday 10 March 2006 11:27, you wrote:
> Dear Atte,
> First, I thank you a lot for your help.
> But, I'm very sorry, but I haven't understand the procedure.
> I will explain you clearly what it mean .
> Our product has a default factory port for the embedded TCP server. The
> user can change this port with a configuration software if this is
> necessary.
> I have a global_pcb that I use in all my application (global variable, only
> on PCB in all my application).

In general you shouldn't be using a global variable for everything unless you
are really sure about what you are doing.

> When I want to change the TCP server port I have a problem.
> I have seen you correctly described how I must proceed but it doesn't work.
> I'm a newbie with the use of LWIP...
> Can you give me again a methode to change the port of my server ?
> To change port I have used the method :
> tcp_bind(global_pcb, IP_ADDR_ANY, port_configuration);
> global_pcb = tcp_listen(global_pcb);
> tcp_accept(global_pcb, config_server_ip_accept);
> But you said this isn't the correct way...
> Do you think I must use this method ?
> temp_pcb = tcp_listen(global_pcb);
> tcp_close(global_pcb);
> global_pcb=temp_pcb;
> tcp_bind(global_pcb, IP_ADDR_ANY, port_configuration);
> tcp_accept(global_pcb, config_server_ip_accept);
> Is it correct do you have a code suggestion ?

That's wrong again. Now you're creating a connection when you really just
 want to open a port.

First long explanation, then some example code.

When you bind()  a pcb to a port you just tell the stack that this pcb refers
to this local port. No connection is created. When you call listen(), you
tell the network stack that whenever a connection attempt to this port is
made, a new connection should be created and the associated pcb (let's call
it client pcb) returned to you. So, and this is the important point, the
client pcb is a completely separate object from the listening pcb.

Now you have two pcbs. The listening pcb still doesn't represent any kind of
 a connection. It's just an open port. The client pcb on the other hand
 represents a connection that the client initiated and you accept()ed. You
 handle the client pcb just like any other tcp connection and then close() it
 when you're done with it. No messing with the server pcb in any point.

When you want to re-bind the server, you close() the server pcb, open it
 again and bind() it to some other port. And now no touching to the client

And the promised example code:

To handle incoming connections:

temp_pcb = tcp_listen(global_pcb);
tcp_accept(temp_pcb, config_server_ip_accept);
/* Do stuff here */

To re-bind the listening pcb to a different port (actually close the old pcb
and open a new pcb and bind it to the new port):

global_pcb = tcp_new()
 tcp_bind(global_pcb, IP_ADDR_ANY, new_port);

PS. If you post a question to the list, post also any further questions to
 the list. I won't answer personal mails concerning lwIP. Also it's bad
 netiquette to take a discussion from a mailing list to personal e-mail.

reply via email to

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