TsgcWebSocketServer | Server Send Text Message

Once client has connected to server, server can send text messages. To send a Text Message, just call WriteData() method to send a message to a single client or use Broadcast to send a message to all clients.

 

Send a Text Message

Call To WriteData() method and send a Text message.


TsgcWebSocketServer1.WriteData('guid', 'My First sgcWebSockets Message!.');

If QueueOptions.Text has a different value from qmNone, instead of be processed on the same thread that is called, it will be processed on a secondary thread. By default this option is disabled.

 

QueueOptions doesn't work if the property IOHandlerOptions.IOHandlerType = iohIOCP (due to the IOCP architecture, this feature is not supported).

 

 

You can call to WriteData() method from TsgcWSConnection too, example: send a message to client when connects to server.

 


procedure OnConnect(Connection: TsgcWSConnection);
begin
  Connection.WriteData('Hello From Server');
end;

 

Send a message to ALL connected clients

Call To Broadcast() method to send a Text message to all connected clients.

 


TsgcWebSocketServer1.Broadcast('Hello From Server');