TsgcWebSocketClient | Receive Text Messages

When client receives a Text Message, OnMessage event is fired, just read Text parameter to know the string of message received.


procedure OnMessage(Connection: TsgcWSConnection; const Text: string);
begin
  ShowMessage('Message Received from Server: ' + Text);
end;

By default, client uses neAsynchronous method to dispatch OnMessage event, this means that this event is executed on the context of Main Thread, so it's thread-safe to update any control of a form for example.

 

If your client receives lots of messages or you need to control the synchronization with other threads, set NotifyEvents property to neNoSync, this means that OnMessage event will be executed on the context of connection thread, so if you require to update any control of a form or access shared objects, you must implement your own synchronization methods.