Jump to content


Photo

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


  • Please log in to reply
28 replies to this topic

#1 Oliver Morsch

Oliver Morsch

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 274 posts
  • LocationGermany

Posted 16 June 2013 - 03:03 AM

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
 

Attached File  MsgSrv.png   188.13KB   826 downloads

Attached File  MsgSrv.zip   2.85MB   806 downloads

 


  • 7

#2 Alberto vesx

Alberto vesx

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 495 posts

Posted 16 June 2013 - 05:59 PM

Very interesting. I am going to try it.


  • 0

#3 logisticasoft

logisticasoft

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 217 posts

Posted 26 May 2014 - 02:50 AM

Hello with delphi x2 professional also works


  • 0

Carlos Ramirez

ramirez.carlos@yahoo.com


#4 RobYost

RobYost

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 212 posts
  • LocationFlorida, USA

Posted 25 January 2018 - 07:36 PM

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.


  • 0

http://unigui.mirahe.../wiki/Main_Page

Please add any utilities you think are useful. I will try to keep the wiki organized.


#5 Oliver Morsch

Oliver Morsch

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 274 posts
  • LocationGermany

Posted 26 January 2018 - 09:14 AM

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.


  • 0

#6 Oliver Morsch

Oliver Morsch

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 274 posts
  • LocationGermany

Posted 18 February 2018 - 01:57 PM

Here is a new version using UTF-8 encoding (-> no problem with special characters):

 

 

Attached Files


  • 0

#7 A.Soltani

A.Soltani

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 157 posts
  • LocationTehran-Iran

Posted 19 February 2018 - 01:20 PM

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.

Attached Files

  • Attached File  1.jpg   4.71KB   6 downloads

  • 0

#8 Oliver Morsch

Oliver Morsch

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 274 posts
  • LocationGermany

Posted 19 February 2018 - 03:36 PM

What is in "edtBaseURL.Text", ends it with a "/"?


  • 0

#9 A.Soltani

A.Soltani

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 157 posts
  • LocationTehran-Iran

Posted 19 February 2018 - 06:13 PM

 

What is in "edtBaseURL.Text", ends it with a "/"?

 

 

 

I create it.

I replace "http://127.0.0.1:8070/"with 'https://My Ip :8070' and then check it.

The edtBaseURL.Text value is (https://MyIp :8070/sessions) 

But I have problem yet.

 

Best Regards.

Attached Files

  • Attached File  1.jpg   121.49KB   5 downloads

  • 0

#10 Oliver Morsch

Oliver Morsch

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 274 posts
  • LocationGermany

Posted 19 February 2018 - 06:49 PM

Show me the procedure TfrmMsgCliCtrl.UniFormCreate

In the code above there is a / missing at the end

Should be https://MyIp:8070/
  • 0

#11 A.Soltani

A.Soltani

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 157 posts
  • LocationTehran-Iran

Posted 19 February 2018 - 06:52 PM

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;

  • 0

#12 Oliver Morsch

Oliver Morsch

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 274 posts
  • LocationGermany

Posted 19 February 2018 - 07:01 PM

OK there is the "/".

Have you changed MsgServer to SSL too?
  • 0

#13 A.Soltani

A.Soltani

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 157 posts
  • LocationTehran-Iran

Posted 19 February 2018 - 07:06 PM

I replace in one procedure 

http://localhost  with (https://My IP).

 

 

But now set all of them and send result for you.

 

 

Best Regards.


  • 0

#14 Oliver Morsch

Oliver Morsch

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 274 posts
  • LocationGermany

Posted 19 February 2018 - 07:15 PM

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

#15 A.Soltani

A.Soltani

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 157 posts
  • LocationTehran-Iran

Posted 19 February 2018 - 07:17 PM

I change all of them,and run on server.

 

Then run client program on the client.

 

But don't fixed.

Attached Files

  • Attached File  2.jpg   54.26KB   6 downloads
  • Attached File  1.jpg   106.11KB   6 downloads

  • 0

#16 A.Soltani

A.Soltani

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 157 posts
  • LocationTehran-Iran

Posted 19 February 2018 - 07:18 PM

 

 

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

 

 

No.

How to I do it?


  • 0

#17 Oliver Morsch

Oliver Morsch

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 274 posts
  • LocationGermany

Posted 19 February 2018 - 07:49 PM

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

But I have never made this.
  • 0

#18 A.Soltani

A.Soltani

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 157 posts
  • LocationTehran-Iran

Posted 21 February 2018 - 07:41 PM

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.


  • 0

#19 A.Soltani

A.Soltani

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 157 posts
  • LocationTehran-Iran

Posted 22 February 2018 - 09:22 PM

Hi

 

Now I have an problem.

 

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

 

 

Best Regards.

Attached Files


  • 0

#20 Oliver Morsch

Oliver Morsch

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 274 posts
  • LocationGermany

Posted 22 February 2018 - 09:47 PM

Which browser(s)?

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users