I know that what I describe below is not technically multicasting, but I lack a better description of what I am trying to do.
I currently have a TIdTCPServer with an OnExecute that reads the incoming message, generates the response messages into a thread safe queue and then calls a function to step through the queue and send the messages back to the client. This part of the code is working and allows clients to request sets of data.
When a client changes an object on the server, I want all of the clients notified of this change. The code currently adds the notification message to each queue for each connection. My problem is that OnExecute is not looped, so the call to send messages on the queue is not called until the Server receives a message from the Client.
Is there a way to get OnExecute to loop? Or a way to trigger an OnExecute for a connection I know I have queued messages for?
My procedure TWinSocketSession object has a reference to the connection and includes the code for the outgoing message Queue. It also has a procedure called SendMessages that steps through the queue and calls Connection.Write. Below is my OnExecute procedure.
procedure TWinServerSession.IdTCPServer1Execute(AThread: TIdPeerThread);
Var
i: Integer;
strMessage: String;
begin
//find the Socket Session for connection
for i := 0 to m_usClientCount do
begin
if m_mWinSocketSession[i]<>Nil then
if ( m_mWinSocketSession[i].Connection = Athread.Connection ) then break;
end;
//read the message
strMessage := m_mWinSocketSession[i].Connection.ReadLn(#0,25,-1);
//parse the message and populate the Queue with outgoing messages
m_mWinSocketSession[i].ParseInString(strMessage);
//send all of the outgoing messages
m_mWinSocketSession[i].SendMessages;
end;