error comparing values in TMSChat demo

Hi guys,

i must be missing something here.


procedure TForm43.WebSocketClient1DataReceived(Sender: TObject; Origin: string;
  SocketData: TJSObjectRecord);
var
  sl: TStringList;
  s,myMessage: String;
  msg: TMessage;
  i: Integer;
begin

  s := SocketData.jsobject.toString;
  //showmessage(s);
  sl := TStringList.Create;
      i:= CompareStr('fish','fish');
    //showmessage(intToStr(i));
  try
    sl.Delimiter := '~';
    sl.StrictDelimiter := true;
    sl.DelimitedText := s;
    myMessage := sl[2].ToLower;
    WebListBox1.Items := sl;
    i:= CompareStr('demo',sl[2]);
    if i=0 then showmessage('demo is the message');
    if (sl.Count > 2) and (sl[1] <> WebChatBox1.Username) then
    begin


      msg := WebChatBox1.Messages.Add;
      msg.ChatMessage := sl[2];
      msg.Sender := sl[1];
      msg.Color := HTMLToColor(sl[0]);

    end;
  finally
    sl.Free;
  end;
end;

i am presumimngsl[2] is a string there when a message is sent 'demo' I should get the alert as i:= CompareStr('demo',sl[2]); should return 0.

Also can I access the chatServer created with the demo from a Delphi FMX project ?

I am not sure what you mean with "presumimng sl[2] is a string"? You control how you format the message (as string) when you send it, so it is up to your code to interpret the string returned according to the format you used for sending.

For your other question, do I understand correct you want to create an FMX client app that will connect to and use the websocket chat server?

  1. Shouldn’t

i:= CompareStr('demo',sl[2]);

Result in 0 ?

  1. Yes. Can I connect to the server.eye service from a FMX app.

What does
console.log(sl[2])
show?

Hi Bruno,

I tried console.log(sl[2].length) if I send demo it shows 5. There is a extra blank char in the string.

Problem solved.

Corrected with

    myMessage := sl[2];
    SetLength(myMessage,LENGTH(myMessage)-1)   ;
    WebListBox1.Items := sl;
    i:= CompareStr('demo',myMessage);
    if i=0 then showmessage('demo is the message');
    console.log(myMessage.length);
    

Is this possible ? Is there a component to add or use an existing one ?

I'm not sure what you mean with this question. Possible what ?

Also can I access the chatServer created with the demo from a Delphi FMX project ?
ie the sever.exe.
If I compile this and run on my server and open the ports can I access from both TMS app & FMX app.

Hope this makes sense

The built-in Delphi socket components won't work out of the box with web sockets. Either you could add this protocol on top of an indy socket component or use a component mentioned in this article: