Limit tcp_listen to single connection

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Limit tcp_listen to single connection

Rick Culver
Is there a way to limit the tcp_listen function to only accept a single connection.  I would like to limit a specific port to accept the first connection request and then refuse any additional connections until the first connection has been closed.  Does anyone know of a way to do this?
 

_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Limit tcp_listen to single connection

S. Ali Tokmen
Hello
 
If you want to refuse all connections when one connection is active, do the following in your while(true) kind of loop:
  1. Do all necessary actions you need to before accepting connections (socket, listen, ...)
  2. Call accept. This will wait until a TCP connection is established.
  3. Once connection has been established (accept has returned), call close on the socket you were listening on.
  4. Do all send and recv calls with the TCP connection (= the socket that accept had returned).
  5. close the TCP connection's socket and loop
Hope this helps
 
GSM (fr): +33 66 43 00 555 [Bouygues Telecom]
GSM (tr): +90 555 266 52 73 [Avea]
 
My AIM, ICQ, MSN Messenger, and Yahoo IM
contact details are on http://contact.ali.tokmen.com/
 
 
----- Original Message -----
Sent: Wednesday, October 10, 2007 8:46 PM
Subject: [lwip-users] Limit tcp_listen to single connection

Is there a way to limit the tcp_listen function to only accept a single connection.  I would like to limit a specific port to accept the first connection request and then refuse any additional connections until the first connection has been closed.  Does anyone know of a way to do this?
 


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

_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Limit tcp_listen to single connection

Frédéric BERNON-2
In reply to this post by Rick Culver
Hi,
 
Except set MEMP_NUM_TCP_PCB=1 in your lwipopts.h, I don't think there is a way to do that with tcp_listen. Even in socket layer, with "lwip_listen(int s, int backlog)", the "backlog" parameter is not used. But you can close as soon as possible any new connection: to do that, you can use a boolean initialized to false, and in "accept" callback (set by tcp_accept), you do something like this:
 
int connected=0;
 
static err_t accept_function(void *arg, struct tcp_pcb *newpcb, err_t err)
{ if (connected) {
    tcp_close(newpcb);
  } else {
    connected=1;
    /* your normal accept behavior */
  }
}
 
and when you have finish to use your "single" connection, you reset connected to 0.
 

----- Original Message -----

Sent: Wednesday, October 10, 2007 8:46 PM
Subject: [lwip-users] Limit tcp_listen to single connection

Is there a way to limit the tcp_listen function to only accept a single connection.  I would like to limit a specific port to accept the first connection request and then refuse any additional connections until the first connection has been closed.  Does anyone know of a way to do this?
 


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

_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Limit tcp_listen to single connection

goldsimon@gmx.de
Why not close the listening pcb in your accept function? And then set it up again after closing the other connection (tcp_err gets called if you don't close it yourself).


Hi,
 
Except set MEMP_NUM_TCP_PCB=1 in your lwipopts.h, I don't think there is a way to do that with tcp_listen. Even in socket layer, with "lwip_listen(int s, int backlog)", the "backlog" parameter is not used. But you can close as soon as possible any new connection: to do that, you can use a boolean initialized to false, and in "accept" callback (set by tcp_accept), you do something like this:
 
int connected=0;
 
static err_t accept_function(void *arg, struct tcp_pcb *newpcb, err_t err)
{ if (connected) {
    tcp_close(newpcb);
  } else {
    connected=1;
    /* your normal accept behavior */
  }
}
 
and when you have finish to use your "single" connection, you reset connected to 0.
 

----- Original Message -----

Sent: Wednesday, October 10, 2007 8:46 PM
Subject: [lwip-users] Limit tcp_listen to single connection

Is there a way to limit the tcp_listen function to only accept a single connection.  I would like to limit a specific port to accept the first connection request and then refuse any additional connections until the first connection has been closed.  Does anyone know of a way to do this?
 



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


_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Limit tcp_listen to single connection

Rick Culver
Simon,
Based on the input received and from what I know of the lwip stack used in "RAW API" it looks like this would be the best approach.  I will give it a try and see how it works.  Thanks for your input.
Rick
 
----- Original Message -----
Sent: Wednesday, October 10, 2007 2:56 PM
Subject: Re: [lwip-users] Limit tcp_listen to single connection

Why not close the listening pcb in your accept function? And then set it up again after closing the other connection (tcp_err gets called if you don't close it yourself).


Hi,
 
Except set MEMP_NUM_TCP_PCB=1 in your lwipopts.h, I don't think there is a way to do that with tcp_listen. Even in socket layer, with "lwip_listen(int s, int backlog)", the "backlog" parameter is not used. But you can close as soon as possible any new connection: to do that, you can use a boolean initialized to false, and in "accept" callback (set by tcp_accept), you do something like this:
 
int connected=0;
 
static err_t accept_function(void *arg, struct tcp_pcb *newpcb, err_t err)
{ if (connected) {
    tcp_close(newpcb);
  } else {
    connected=1;
    /* your normal accept behavior */
  }
}
 
and when you have finish to use your "single" connection, you reset connected to 0.
 

----- Original Message -----

Sent: Wednesday, October 10, 2007 8:46 PM
Subject: [lwip-users] Limit tcp_listen to single connection

Is there a way to limit the tcp_listen function to only accept a single connection.  I would like to limit a specific port to accept the first connection request and then refuse any additional connections until the first connection has been closed.  Does anyone know of a way to do this?
 



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


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

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