Page 1 of 1

SimpleServer demo

Posted: Tue Mar 24, 2020 5:18 pm
by lasaranza
Hi,

I tried the Simpleserver demo and was able to connect to the webscoket server without issues. Then I tried to send a message using CEFServerComponent.SendWebSocketMessage but got issues on how the string is displayed in the websocket website. My code looks like this:

Code: Select all

procedure TSimpleServerFrm.CEFServerComponent1WebSocketConnected(
  Sender: TObject; const server: ICefServer; connection_id: Integer);
var
  TempData: string;
begin
  TempData := 'Hey connected!'; 
  CEFServerComponent1.SendWebSocketMessage(connection_id, @TempData[1], length(TempData) * SizeOf(Char));
end;
but the message that is displayed in https://www.websocket.org/echo.html looks like below:
Image

Do you have an idea how to send the message correctly?

Thank you in advance.

Re: SimpleServer demo

Posted: Tue Mar 24, 2020 5:35 pm
by salvadordf
Hi,

TempData is a unicode string that uses 2 bytes per character. Try converting it to AnsiString or UTF8 if your client supports that format.

Re: SimpleServer demo

Posted: Tue Mar 24, 2020 5:59 pm
by lasaranza
I see, I will try it. Thank you for your quick reply.

Re: SimpleServer demo

Posted: Thu Mar 26, 2020 3:10 pm
by lasaranza
Another question related to websocket. My application is using a websocket server(TsgcWebSocketHTTPServer)(version 4.0.2) and I wonder if there is specific version that needs to be used with dcef4. I don't know how they are related but after I upgraded to dcef4, I got a random error when writing data to websocket channel connection. I don't know if this is related to using cef as multiprocess. Because of this error, I am thinking of replacing it with TCEFServerComponent component.

Re: SimpleServer demo

Posted: Fri Mar 27, 2020 10:31 am
by salvadordf
It's hard to guess what is the problem but assume that all events in CEF4Delphi components are executed in a different thread just to avoid thread-safety issues.