Demos | Client SocketIO

This demo shows how connect to a Socket.IO Server. Requires a TsgcWebSocketClient to handle WebSocket / TCP protocols.

 

Configuration

 


SOCKETIO.Client := WSClient;
WSClient.Host := 'socketio-chat-h9jt.herokuapp.com';
WSClient.Port := 443;
WSClient.Options.Parameters := '/';
WSClient.Specifications.RFC6455 := True;
WSClient.TLS := True;

Send Messages

Socket.IO uses TsgcWebSocketClient to send messages to server, so just call WriteData and pass as a parameter the JSON message to socket.io server

 


WSClient.WriteData('42["new message", "' +  txtSocketIOMessage.Text + '"]');

 

Receive Messages

The messages received as the flow of connection is handled by TsgcWebSocketClient, so use this component to read the messages sent from server and to know if connection is active or not.

 


procedure TfrmWebSocketClient.WSClientMessage(Connection: TsgcWSConnection;
  const Text: string);
begin
  DoLog(Text);
end;