🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
9 messages
9 total messages Started by Joe St. Onge Mon, 21 Jun 2004 19:41
TServerSocket - Limiting Connections
#5753
Author: Joe St. Onge
Date: Mon, 21 Jun 2004 19:41
15 lines
1577 bytes
I have a application which accepts external connections from remote units,
this application is working great.  There is a problem when more than one
unit attempts to connect to the server at the same time.  The application is
designed for servicing one remote unit at a time.

What I need to do is to limit the Server Connections to 1 at a time.  The
application set the Server Socket to port 3002, when a remote unit connects
to 3002 the servicing begins, I need to prevent the Server Socket from
accepting another connection until that remote unit completes.

Anyone know how to restrict the number of connections that a server socket
will accept?

Regards,
Joe
Re: TServerSocket - Limiting Connections
#5754
Author: Hans Galema
Date: Mon, 21 Jun 2004 20:46
8 lines
1152 bytes
Joe St. Onge wrote:

> Anyone know how to restrict the number of connections that a server socket
> will accept?

The way to to that is to Close the Socket that comes in as second.

Hans.
Re: TServerSocket - Limiting Connections
#5755
Author: Remy Lebeau (TeamB)
Date: Mon, 21 Jun 2004 22:05
11 lines
1272 bytes
"Joe St. Onge" <jstonge@nel-techlabs.com> wrote in message
news:40d739d9@newsgroups.borland.com...

> Anyone know how to restrict the number of connections
> that a server socket will accept?

Use the OnAccept event to Close() the new connection.


Gambit
Re: TServerSocket - Limiting Connections
#5758
Author: Joe St. Onge
Date: Tue, 22 Jun 2004 14:59
49 lines
2302 bytes
Hi Remy,

I did what you said and received the following error "exception class
EListError with message 'List index out of bounds (0)' "

This is the OnAccept code that I used...

void __fastcall TMainForm::ChanServerSocketAccept(TObject *Sender,
      TCustomWinSocket *Socket)
   {
   if (MainForm->Connections++)
      ChanServerSocket->Close();
   }

I then tried changing the routine to

void __fastcall TMainForm::ChanServerSocketAccept(TObject *Sender,
      TCustomWinSocket *Socket)
   {
   if (MainForm->Connections)
      MainForm->ChanServerSocket->Socket->Connections[1]->Close();
   }

and received the following error "exception class EListError with message
'Asynchronous socket error 10053' "

Isn't there a method to shutoff listening after accepting a connection and
keeping the current connection active???

Thanks,
Joe



"Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com> wrote in message
news:40d75c9d$1@newsgroups.borland.com...
>
> "Joe St. Onge" <jstonge@nel-techlabs.com> wrote in message
> news:40d739d9@newsgroups.borland.com...
>
> > Anyone know how to restrict the number of connections
> > that a server socket will accept?
>
> Use the OnAccept event to Close() the new connection.
>
>
> Gambit
>
>
Re: TServerSocket - Limiting Connections
#5759
Author: Hans Galema
Date: Tue, 22 Jun 2004 15:08
20 lines
1585 bytes
Joe St. Onge wrote:

> Hi Remy,

A selective greeting for one of the replyers.

> void __fastcall TMainForm::ChanServerSocketAccept(TObject *Sender,
>       TCustomWinSocket *Socket)
>    {
>    if (MainForm->Connections++)
>       ChanServerSocket->Close();

Why do you use a MainForm->Connection ? TServerSocket keeps
track of the number of active connections. And why do you
close The ChanServerSocket instead of the actual Socket;

	if ( ChanServerSocket->Socket->ActiveConnections )
		Socket->Close();

Hans.
Re: TServerSocket - Limiting Connections
#5760
Author: Joe St. Onge
Date: Tue, 22 Jun 2004 15:23
38 lines
2227 bytes
Hans,

I modified my code as you suggested...

void __fastcall TMainForm::ChanServerSocketAccept(TObject *Sender,
      TCustomWinSocket *Socket)
   {
   if (ChanServerSocket->Socket->ActiveConnections > 1)
      Socket->Close();
   }

What happened is that the Socket->Close() also closed my existing socket.  I
am attempting to keep one connection per socket and not accept any more
connections on that socket until the first has finished...


"Hans Galema" <dontusethis@dontusethis.nl> wrote in message
news:40d84b21$1@newsgroups.borland.com...
> Joe St. Onge wrote:
>
> > Hi Remy,
>
> A selective greeting for one of the replyers.
>
> > void __fastcall TMainForm::ChanServerSocketAccept(TObject *Sender,
> >       TCustomWinSocket *Socket)
> >    {
> >    if (MainForm->Connections++)
> >       ChanServerSocket->Close();
>
> Why do you use a MainForm->Connection ? TServerSocket keeps
> track of the number of active connections. And why do you
> close The ChanServerSocket instead of the actual Socket;
>
> if ( ChanServerSocket->Socket->ActiveConnections )
> Socket->Close();
>
> Hans.
Re: TServerSocket - Limiting Connections
#5762
Author: Remy Lebeau (TeamB)
Date: Tue, 22 Jun 2004 16:54
17 lines
1296 bytes
"Joe St. Onge" <jstonge@nel-techlabs.com> wrote in message
news:40d84965$1@newsgroups.borland.com...

>       ChanServerSocket->Close();

Change that to this instead:

    Socket->Close();

> Isn't there a method to shutoff listening after accepting a
> connection and keeping the current connection active???

No.


Gambit
Re: TServerSocket - Limiting Connections
#5764
Author: Remy Lebeau (TeamB)
Date: Tue, 22 Jun 2004 16:58
15 lines
1470 bytes
"Hans Galema" <dontusethis@dontusethis.nl> wrote in message
news:40d84b21$1@newsgroups.borland.com...

> if ( ChanServerSocket->Socket->ActiveConnections )

The ActiveConnections property is incremented before the OnAccept event is
triggered.  Your code would effectively disconnect *all* incoming
connections, not allowing a single connection to remain active.  You should
be doing this instead:

    if ( ChanServerSocket->Socket->ActiveConnections > 1 )


Gambit
Re: TServerSocket - Limiting Connections
#5763
Author: Remy Lebeau (TeamB)
Date: Tue, 22 Jun 2004 17:01
22 lines
1916 bytes
"Joe St. Onge" <jstonge@nel-techlabs.com> wrote in message
news:40d84edf$1@newsgroups.borland.com...

> What happened is that the Socket->Close() also closed my existing socket.

Not possible.  Every connection has its own TCustomWinSocket instance.
Disconnecting one socket does not have any effect on other existing sockets.

> I am attempting to keep one connection per socket and
> not accept any more connections on that socket until the
> first has finished...

Worse case scenerio, you may just have to resort to changing to a different
component, or even just acessing the WinSock API directly.  TServerSocket
was not designed to handle only a single connection, but instead handles
multiple connections.  It can be used for a single connection, but at the
cost of first accepting all connections and then closing any connection that
you don't want.


Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads