Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

SimpleServer demo

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

SimpleServer demo

Post 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.
You do not have the required permissions to view the files attached to this post.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: SimpleServer demo

Post 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.
lasaranza
Posts: 23
Joined: Tue Feb 25, 2020 8:27 am

Re: SimpleServer demo

Post by lasaranza »

I see, I will try it. Thank you for your quick reply.
lasaranza
Posts: 23
Joined: Tue Feb 25, 2020 8:27 am

Re: SimpleServer demo

Post 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.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: SimpleServer demo

Post 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.
Post Reply