🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
3 messages
3 total messages Started by mike Sat, 07 Aug 2004 16:18
How To Send To Multiple Clients
#5474
Author: mike
Date: Sat, 07 Aug 2004 16:18
54 lines
2729 bytes
Hope someone can help me with this, another socket problem.

I have a single Server Socket running in blocking mode, so each client has
its own thread. Everything I have tested works great.

Now, under some conditions the Server receives a message and the Server must
send a message to all the connected clients. So I declared a public routine
SendToAllClients(). The information that needs to be sent to all the clients
is also placed in a public variable.

So what I then do is the following:

In the receiving Server Thread;

           for( int i = 0; i <
Form1->ServerSocket2->Socket->ActiveConnections; i++ )
           {

                TServerClientWinSocket *ClientSocket =
static_cast<TServerClientWinSocket*>(
Form1->ServerSocket2->Socket->Connections[ i ] )           ;

                TMyServerThread *Thread              =
static_cast<TMyServerThread*>(
Form1->ServerSocket2->Socket->GetClientThread( ClientSocket ) ) ;



                if( Thread )
                {
                         Thread->InfoToSendToAllClients     =
DataToSendOutToClient           ;

                                                       ;
                        Thread->SendAnActionToSendToAClient()
;
                    }
                }

           }

So what I am trying to do is send the data contained in
DataToSendOutToClient to all the clients connected. Now everything seems to
work fine, that is the  public routine Thread->SendAnActionToSendToAClient()
does the send but what happens is shortly after the actual socket send takes
place the socket is dropped. There is no exception or error that I can see,
it just simply drops.

So my question is, in a threaded server socket, what is the proper way to
send a message to all connected clients.

Thanks for any information.

Mike
Re: How To Send To Multiple Clients
#5475
Author: Remy Lebeau (TeamB)
Date: Sun, 08 Aug 2004 21:27
23 lines
1833 bytes
"mike" <mfbrowne@earthlink.net> wrote in message
news:41166225$1@newsgroups.borland.com...

> what happens is shortly after the actual socket send takes
> place the socket is dropped. There is no exception or
> error that I can see, it just simply drops.

Please show your actual sending code.  Sockets don't just drop without
saying why, so there has to be an error being reported somewhere..

> So my question is, in a threaded server socket, what is the
> proper way to send a message to all connected clients.

Exactly what you are already doing - looping through the server's
connections sending to each one.  Although I have to question your use of
InfoToSendToAllClients.  What happens if a thread has not sent
InfoToSendToAllClients yet when another multi-client message comes through?
Is InfoToSendToAllClients overwritten?  Sounds like you need to implement
some kind of queing system, if you are not already doing so.


Gambit
Re: How To Send To Multiple Clients
#5479
Author: mike
Date: Tue, 10 Aug 2004 14:52
38 lines
2340 bytes
Remy,

Thanks for answering, but I was being really stupid. On the receiving end of
the broadcast I was closing the socket. It was test code from long ago that
I had forgotten about. I knew it was something stupid and it did not make
sense to me at all, then I found the test code and went "DAh".

Again thanks.

Mike
"Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com> wrote in message
news:41169ab1$1@newsgroups.borland.com...
>
> "mike" <mfbrowne@earthlink.net> wrote in message
> news:41166225$1@newsgroups.borland.com...
>
> > what happens is shortly after the actual socket send takes
> > place the socket is dropped. There is no exception or
> > error that I can see, it just simply drops.
>
> Please show your actual sending code.  Sockets don't just drop without
> saying why, so there has to be an error being reported somewhere..
>
> > So my question is, in a threaded server socket, what is the
> > proper way to send a message to all connected clients.
>
> Exactly what you are already doing - looping through the server's
> connections sending to each one.  Although I have to question your use of
> InfoToSendToAllClients.  What happens if a thread has not sent
> InfoToSendToAllClients yet when another multi-client message comes
through?
> Is InfoToSendToAllClients overwritten?  Sounds like you need to implement
> some kind of queing system, if you are not already doing so.
>
>
> 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