SimpleServer demo

Post Reply
lasaranza
Posts: 7
Joined: Tue Feb 25, 2020 8:27 am

SimpleServer demo

Post by lasaranza » Tue Mar 24, 2020 5:18 pm

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.
You do not have the required permissions to view the files attached to this post.

User avatar
salvadordf
Posts: 2223
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: SimpleServer demo

Post by salvadordf » Tue Mar 24, 2020 5:35 pm

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.

lasaranza
Posts: 7
Joined: Tue Feb 25, 2020 8:27 am

Re: SimpleServer demo

Post by lasaranza » Tue Mar 24, 2020 5:59 pm

I see, I will try it. Thank you for your quick reply.

lasaranza
Posts: 7
Joined: Tue Feb 25, 2020 8:27 am

Re: SimpleServer demo

Post by lasaranza » Thu Mar 26, 2020 3:10 pm

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.

User avatar
salvadordf
Posts: 2223
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: SimpleServer demo

Post by salvadordf » Fri Mar 27, 2020 10:31 am

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.

Post Reply