Jump to content
Martybartfast

ICS Web Sockets send from server

Recommended Posts

I'm using ICS Web Sockets, and everything is working good so far - browsers connect to my server, and the ICS "echo" sample works fine.

 

However, I need to send an unsolicited string from the server to all connected clients. Anyone know how to do this? I've tried and tried, and can't find any way to access the web socket clients. If I just do "Webserver.client[n].sendstr(s);" then the browser just disconnects.

 

What I'm trying to do this something like this:

WebSocketServer: TWSocketServer;
...
procedure THttpGUI.Start;
begin
...
if not(assigned(WebSocketServer)) then    // Don't do if already created
  begin
    WebSocketServer := TWSocketServer.Create(nil);   // Create the WebSocket server
    WebSocketServer.Proto := 'tcp';             // TCP/IP protocol
    WebSocketServer.ClientClass := TWebSockSrvClient; // Web socket
    WebSocketServer.Banner := '';     // Remove banner because we handle websocket handshake
    WebSocketServer.OnBgException := WebSocketServer_BgException;
    WebSocketServer.OnClientConnect := WebSocketServer_ClientConnect;
    WebSocketServer.OnClientDisconnect := WebSocketServer_ClientDisconnect;
  end;
end;
  
  // Connection stuff all works fine, not shown here
  
  ...
  
// Send a string to all connected clients (browsers).
procedure THttpGUI.WebSocket_SendString(s : string);
var
  n : integer;
begin
  if assigned(WebSocketServer) then
  begin
    for n := 0 to WebSocketServer.ClientCount-1 do
    begin
      WebSocketClient[n].sendString(s);       // Something like this!!!
    end;
  end;
end;

 

Share this post


Link to post

He originally posted the question in the ICS forum, but the issue is not with ICS, but with a Javascript web page implementation to display data from the websockets server.

 

Angus

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×