Jump to content

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


Oliver Morsch

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 8
Link to comment
Share on other sites

  • 11 months later...
  • 3 years later...

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.

Link to comment
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.

Link to comment
Share on other sites

  • 4 weeks later...

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

Link to comment
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;

 

Link to comment
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.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...