Jump to content
uniGUI Discussion Forums
Oliver Morsch

MessageServer: "push" messages from server to client (long polling)

Recommended Posts

Hi!

I have developped a message server, so you can send "push" messages at any time from the server to the web client (using long polling). You can also send messages from a client to another client (with message server in the middle).

The message server is a standalone app. You must run MsgSrv.exe and MsgCli.Exe (second is a uniGui project).

I was using Delphi XE3 (with generics, class vars, ...), so i have included the .exe, because the message server does not compile in old delphi versions.

For details see the commented screenshot.

Regards
Oliver
 

post-147-0-22307200-1371351763_thumb.png

MsgSrv.zip

 

  • Upvote 7

Share this post


Link to post
Share on other sites

I just found this thread.  When I tried to compile the client with XE6:

 

 

procedure TfrmMsgCliCtrl.btnSelectTargetClick(Sender: TObject);
begin
  frmSelectTargetSession.ShowModal( procedure (Res: Integer)
    begin
      if Res = mrOK then begin
        edtTargetSess.Text := frmSelectTargetSession.lbSessions.Text;
      end;
    end
    );
end;

[dcc32 Error] UfrmMsgCliCtrl.pas(105): E2250 There is no overloaded version of 'ShowModal' that can be called with these arguments

 

Does someone know how to fix the syntax for XE6, or am I doing something wrong?

 

Thanks.

Share this post


Link to post
Share on other sites
procedure TfrmMsgCliCtrl.btnSelectTargetClick(Sender: TObject);
begin
  frmSelectTargetSession.ShowModal( procedure (Sender: TComponent; Res: Integer)  // <---
    begin
      if Res = mrOK then begin
        edtTargetSess.Text := frmSelectTargetSession.lbSessions.Text;
      end;
    end
    );
end;

It has nothing to do with XE6, it's a change in UniGUI.

Share this post


Link to post
Share on other sites

Hi

 

I use SSL protocol in my project.

I change the code

procedure TfrmMsgCliCtrl.UniFormCreate(Sender: TObject);
var
  S: String;
begin
  // init edits and script:
{  S := 'https://' + StringReplace(UniSession.Host,
    IntToStr(UniServerModule.Port), '8070', []);}

  S:='https://my valid IP:8070';
end;

Now in this line the error ocurred

procedure TfrmSelectTargetSession.UniFormShow(Sender: TObject);
var
  S: String;
begin
  S := edtBaseURL.Text + 'sessions';
  S := httpGetSess.Get(S);
end;

I add below code 

  httpGetSess.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(httpGetSess);
  httpGetSess.HandleRedirects := True;

But don't fixed.

 

Best Regards.

post-4571-0-32317900-1519046421_thumb.jpg

Share this post


Link to post
Share on other sites


procedure TfrmMsgCliCtrl.UniFormCreate(Sender: TObject);
var
S: String;
begin
// init edits and script:
{ S := 'http://' + StringReplace(UniSession.Host, IntToStr(UniServerModule.Port), '8070', []); //alternative?: S := StringReplace(UniSession.URL, IntToStr(UniServerModule.Port), '8070', []);
if Copy(S, Length(S), 1) <> '/' then
S := S + '/';}
S := 'https://x.x.x.155:8070/' ;
Script.Text := StringReplace(Script.Text, '$baseUrl$', S, []);
edtBaseURL.Text := S;

edtSessionID.Text := UniSession.SessionID;
// create objects and init:
FSL := TStringList.Create;
FSL.Add('sid=' + edtSessionID.Text);
FSL.Add('msg=');
end;

 

Share this post


Link to post
Share on other sites

I change all of them,and run on server.

 

Then run client program on the client.

 

But don't fixed.

post-4571-0-41892900-1519067839_thumb.jpg

post-4571-0-46092200-1519067849_thumb.jpg

Share this post


Link to post
Share on other sites

 

 

Did you add SSL component to MsgServer? And use cert? 

 

 

No.

How to I do it?

Share this post


Link to post
Share on other sites

You need a TIdServerIOHandlerSSLOpenSSL, must assign the certs and then assign it to the HttpServer.

 

But I have never made this.

Share this post


Link to post
Share on other sites

HI

 

I could send message from MsgSrv to all client.

procedure TfrmMsgSrvCtrl.FormCreate(Sender: TObject);
var
  LIOHandleSSL: TIdServerIOHandlerSSLOpenSSL;
begin
  FServer := TIdHTTPWebBrokerBridge.Create(Self);
  LIOHandleSSL := TIdServerIOHandlerSSLOpenSSL.Create(FServer);
  LIOHandleSSL.SSLOptions.CertFile := 'cert.cer';
  LIOHandleSSL.SSLOptions.RootCertFile := 'root.crt';
  LIOHandleSSL.SSLOptions.KeyFile := 'key.pem';
  LIOHandleSSL.OnGetPassword := OnGetSSLPassword;
  FServer.IOHandler := LIOHandleSSL;
  FCounter := 1000;
end;
procedure TfrmMsgSrvCtrl.OnGetSSLPassword(var APassword: String);
begin
  APassword := 'The Pass';
end;
Of course  must change  all URL  to URL := Format('https://X.X.X.X:%s/........
 

 

 And now I try to  solve send message from MsgCli to all session.

 

 

Best Regards.

Share this post


Link to post
Share on other sites

Hi

 

Now I have an problem.

 

After  send Message from MsgSrv ,The browser  SSL sign go to red color.

 

 

Best Regards.

post-4571-0-09516600-1519334441_thumb.jpg

post-4571-0-62791700-1519334450_thumb.jpg

Share this post


Link to post
Share on other sites

 

 

Which browser(s)?

 

In Chrome,Because in Firefox I can't recive any message and  ufrMsgSrv  show :(You'r connection is not secure).

 

 

What will be shown by clicking on the "not secure"?

I showed it by picture that attached.

post-4571-0-71917600-1519337033_thumb.jpg

post-4571-0-44770100-1519337203_thumb.jpg

Share this post


Link to post
Share on other sites

Firefox showed this Error:

 

Error code: SSL_ERROR_BAD_CERT_DOMAIN

 

But Chrome don't show any error.

 

Best Regards.

Share this post


Link to post
Share on other sites

post-4571-0-89778400-1519338594_thumb.jpg

 

This Pic is from Chrome.

 

The  ufrMsgSrv  shows :(I am OK!).

 

 

Best Regards.

Share this post


Link to post
Share on other sites

Now I have tested SSL and it works. But Chrome and Firefox show "(certificate) not secure" because of self signed certificate. IE and Edge have no problem after adding the root certificate.

Share this post


Link to post
Share on other sites

×