I see how the BroadcastMessage method works but I can't figure out how to use the callback to send a message to one client from another or the server to one client. Any ideas on this?
SendDataTo which is what
BroadcastMessage is using internally.
In the selector callback you can define which connection should receive the message.
In the second example here you can see how it is being used.
So far as I can see this will send to all connected clients except the client.
How do I send to one specific client in a list of connected clients.
Normally you'd use some sort of identification (IP, unique ID, etc) and use that identification when sending the message.
We've extended the documentation with information on storing custom data:
And following that, sending could be something like:
procedure TForm1.SendMessageToClientWithID(AID, AMessage: string);
TMSFNCWebSocketServer1.SendMessageTo(AMessage, function (AConnection: TTMSFNCWebSocketServerConnection): Boolean
Result := False;
if TMyDataObject(AConnection.UserData).ID = AID then
Result := True;