Jump to content

How to send a text message from ServerModule to all MainForm sessions


Max_name123

Recommended Posts

 

12 hours ago, aristeo said:

Use websockets . I use thia component https://www.esegece.com/ for sending messages from server to clients

I downloaded and installed components, added folders to tools-options-library, threw on the form
sgcWebSocketClient1: TsgcWebSocketClient;
sgcWebSocketServer1: TsgcWebSocketServer;
and errors fell in, the uses compiler swears at: sgcWebSocket_Classes,
sgcWebSocket_Classes_Indy,
sgcWebSocket_Server,
sgcWebSocket,
sgcWebSocket_Client;
What to do mind I will not put!
And another question, is it possible to poll data on a server, for example, in a timer?

P.S.

By the way, I cannot understand why UniGui does not have built-in methods for sending data between the server and sessions ((

Link to comment
Share on other sites

Hi

In attach a small example.

As websocket server, use: <sgcWebSockets\Demos\ServerSentEvents>

and disable this:

procedure TfrmServer.pageMainHTMLTag(Sender: TObject; Tag: TTag; const
    TagString: string; TagParams: TStrings; var ReplaceText: string);
begin
//  if TagString = 'port' then
//    ReplaceText := IntToStr(WSServer.Port)
//  else if TagString = 'host' then
//    ReplaceText := '127.0.0.1';
end;

Add in UniServerModul.CustomFiles (file is not available in the example):

files/sgcWebSockets.min.js

Hope it helps

webSocket.zip

  • Like 1
Link to comment
Share on other sites

@A.soltani

Meaby this helps:

    socket.on('message', function(evt){
      document.getElementById('log').innerHTML = evt.message;
      ajaxRequest(MainForm.window, "_message",["msgStr=" + evt.message]);
    });

 

and this?:

  function start_sse(param) {
    socket = new sgcWebSocket(param);
...

 

I have updated the example, hope it helps you ;-)

 

webSocket.zip

  • Like 1
Link to comment
Share on other sites

Why you are trying extra kod? You can get session list in unigui. look in demos.

Add a property to main form. text, number or record type or what you need. Write set procedure to this property.

Write a sent message procedure. In this procedure has a loop for sessions. and set income param(s) to session's mainform's xxxx property. Thats all.

This can be problem in just hyperserver. 'cos If I'm not wrong, can not get all session list in hyperserver, so can not sent message to all. But this can fix.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...