Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

broadcast message to all connected clients ? #10

Open
DRAMA22 opened this issue Sep 9, 2016 · 3 comments
Open

broadcast message to all connected clients ? #10

DRAMA22 opened this issue Sep 9, 2016 · 3 comments

Comments

@DRAMA22
Copy link

DRAMA22 commented Sep 9, 2016

i am using that way to get some text on server then i try to broadcast back to all connected clients so i try

procedure TForm1.ServerMessageTextReceived(const AContext: TIdServerWSContext;
  const aText: string);
var
  strm: TStringStream;
begin
  ShowMessageInMainthread(aText);
  strm := TStringStream.Create('SERVER: ' + aText);
  //AContext.IOHandler.WriteLn('goi', IndyTextEncoding_UTF8);
  broadcastmessage('goi');
end;

procedure TForm1.broadcastmessage(const text: string);
var
 List: TList;
 i : integer;
begin
List := Server.Contexts.LockList;
try

for I := 0 to List.Count - 1 do
begin
SendCommand(text);
end;

finally
Server.Contexts.UnlockList;
end;

end;

procedure TForm1.SendCommand(const textprm: String);
begin

//what to do here ?
end;


or better yet can i setup tconnection to each connected client ?as we do in normal tcpserver as example 

  **TConnection = class(TIdServerContext)
var to define connections as name etc..**
@andremussche
Copy link
Owner

it is much easier to do this :)
server.SocketIO.EmitEventToAll(C_SERVER_EVENT, SO(['data', 'pushed from
server']) );

see for a demo:

https://github.com/andremussche/DelphiWebsockets/blob/master/Demo/Unit1.pas

2016-09-09 7:26 GMT+02:00 DRAMA22 [email protected]:

i am using that way to get some text on server then i try to broadcast
back to all connected clients so i try

procedure TForm1.ServerMessageTextReceived(const AContext: TIdServerWSContext;
const aText: string);
var
strm: TStringStream;
begin
ShowMessageInMainthread(aText);
strm := TStringStream.Create('SERVER: ' + aText);
//AContext.IOHandler.WriteLn('goi', IndyTextEncoding_UTF8);
broadcastmessage('goi');
end;

procedure TForm1.broadcastmessage(const text: string);
var
List: TList;
i : integer;
begin
List := Server.Contexts.LockList;
try

for I := 0 to List.Count - 1 do
begin
SendCommand(text);
end;

finally
Server.Contexts.UnlockList;
end;

end;

procedure TForm1.SendCommand(const textprm: String);
begin

//what to do here ?
end;

or better yet can i setup tconnection to each connected client ?as we do in normal tcpserver as example

TConnection = class(TIdServerContext)
var to define connections as name etc..


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#10, or mute the
thread
https://github.com/notifications/unsubscribe-auth/AC5IjgZFUBPPoj2EON-KoDD7qcs85YX1ks5qoO3ogaJpZM4J4tiG
.

@DRAMA22
Copy link
Author

DRAMA22 commented Sep 13, 2016

the problem is i need to define connection who is entered to my server with username and id etc.. so i send to each one who matched some condition

@andremussche
Copy link
Owner

Can you please send me a small demo project1 so I can reproduce and debug
the problem?

2016-09-13 9:48 GMT+02:00 DRAMA22 [email protected]:

the problem is i need to define connection who is entered to my server
with username and id etc.. so i send to each one who matched some condition


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#10 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AC5IjsWyXGvehthMbemmf45jxwzebkl2ks5qplUxgaJpZM4J4tiG
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants