Jump to content

Recommended Posts

19 minutes ago, MVakili said:

image.png.072921f156aea692edc45f12a3c4a62d.png

I want to display the internet connection and Ping speed similar to what we see in the image at the top of the program to the user.
Has anyone had any experience in this field?
 

Hello, for ping with javascript try this with:

https://stackoverflow.com/questions/4282151/is-it-possible-to-ping-a-server-from-javascript

 

https://www.geeksforgeeks.org/how-to-ping-a-server-using-javascript/

 

https://www.tutorialspoint.com/how-to-ping-a-server-using-javascript

  • Like 1
Link to comment
Share on other sites

12 minutes ago, irigsoft said:
Thank you for your quick reply
But I don't know how to use these codes in UniGui 
We used to use this method to connect to the Internet

function YourFunctionName : boolean;
  var
     origin : cardinal;
  begin
     result := InternetGetConnectedState(@origin,0);

     //connections origins by origin value
     //NO INTERNET CONNECTION              = 0;
     //INTERNET_CONNECTION_MODEM           = 1;
     //INTERNET_CONNECTION_LAN             = 2;
     //INTERNET_CONNECTION_PROXY           = 4;
     //INTERNET_CONNECTION_MODEM_BUSY      = 8;
  end;

 

Link to comment
Share on other sites

 

Yes, that's correct.
In fact, the problem consists of several parts:
1. Is there a connection to the server?
2. What is the speed of the connection to the server?
3. What is the speed of the connection between the program and the database?
4. What is the CPU processing power?
And similar questions.

 

The goal is actually to be able to check the required aspects on the client side and make the user aware of potential bottlenecks in the operations.
 

Link to comment
Share on other sites

I think this code is useful for checking ping time to a server
 

Function Ping(const Host: string; Port: Integer):Integer;
var
  Started: Tdatetime;
  Http: TIdHTTP;
begin
  Started := Now;
  Http := TIdHTTP.Create(nil);
  try
    try
      Http.Get('http://' + Host + ':' + IntToStr(Port));
      Result:=MilliSecondsBetween(TDateTime.Now, Started);
    except
      // this is expected
    end;
  finally
    Http.Free;
  end;
end;



 

   if IsConnected then
      Caption:='Connected'+IntToStr(Ping('Server',any port))
   Else
      Caption:='Not Connected'

 

Link to comment
Share on other sites

6 minutes ago, MVakili said:
7 minutes ago, Sherzod said:

Hello,

With your uniGUI server as I understand it!?

yes thats correct

I think there are many ways to do this. One of them is to simply send a request to the server using ajaxRequest, and determine the time spent on the response from the server.

Link to comment
Share on other sites

2 minutes ago, Sherzod said:

I think there are many ways to do this. One of them is to simply send a request to the server using ajaxRequest, and determine the time spent on the response from the server.

By sending a few bytes of data.

Link to comment
Share on other sites

Just now, Sherzod said:

No, the ping must be from the client side...

In fact, I want to display the client's connection speed to the software (which is hosted on the server). 
After that, I need to know the speed of the software's connection to the data server (which can be located in different places in our designs). 
And finally, I need to know the status of the server for processing tasks (whether it is involved in heavy processing or not).

image.png.a7c8dc34769991b7375dbb9238b76e58.png

Link to comment
Share on other sites

And finaly

for this 

image.png.72743b2839fae5b49514111d05c1006f.png

you can use this function + Unitimer

function TDMT.Ping2(const AHost: string): Integer;
var
  ICMP: TIdICMPClient;
  Started: Tdatetime;
begin
   Result:=-1;
  Started := Now;
  ICMP := TIdICMPClient.Create(nil);
  try
    ICMP.Host := AHost;
    ICMP.ReceiveTimeout := 2000;
    ICMP.Ping();
    If  (ICMP.ReplyStatus.ReplyStatusType = rsEcho) Then
      Result:=MilliSecondsBetween(TDateTime.Now, Started);

  finally
    ICMP.Free;
  end;
end;

in timer

procedure TMainForm.UniTimer1Timer(Sender: TObject);
Var
   T : Integer;
   
begin
   T:=Ping2('1.1.1.1');
   if T>=0 then
      LPing.Caption:=T.ToString+ ' ms'
   Else
      LPing.Caption:= ' Error';
end;

 

and for program server as @Sherzod guide me we can use this code

Function UniServer(Var RetParams : Tstringlist):Integer;
begin
  With RetParams Do
     Begin
        Add('Memory Used:'+UniServerModule.ServerResources.MemoryUsed.ToString+'/'+UniServerModule.ServerResources.PeakMemoryUsed.ToString);
        Add('Process Memory Used:'+UniServerModule.ServerResources.ProcessMemoryUsed.ToString+'/'+UniServerModule.ServerResources.PeakProcessMemoryUsed.ToString);
        Add('USER Objects:'+UniServerModule.ServerResources.USERObjects.ToString+'/'+UniServerModule.ServerResources.PeakUSERObjects.ToString);
        Add('GDI Objects:'+UniServerModule.ServerResources.GDIObjects.ToString+'/'+UniServerModule.ServerResources.PeakGDIObjects.ToString);
        Add('CPU Usage:'+FloatToStr(UniServerModule.ServerResources.CPUUsage)+'/'+FloatToStr(UniServerModule.ServerResources.PeakCPUUsage));
        Add('Handles:'+UniServerModule.ServerResources.Handles.ToString+'/'+UniServerModule.ServerResources.PeakHandles.ToString);
     End;
end;

 

  • Like 3
Link to comment
Share on other sites

7 hours ago, picyka said:

The problem with these server side functions using the timer is that the unigui session doesn't die.

in timer you can use a variable for counting and 

   Inc(C);
   if C>5 Then
      PingTimer.Enabled:=False;

and in LPing.OnClick

C:=0;
PingTimer.Enabled:=True;

 

  • Like 1
Link to comment
Share on other sites

On 8/5/2023 at 10:31 PM, MVakili said:

And finaly

for this 

image.png.72743b2839fae5b49514111d05c1006f.png

you can use this function + Unitimer

function TDMT.Ping2(const AHost: string): Integer;
var
  ICMP: TIdICMPClient;
  Started: Tdatetime;
begin
   Result:=-1;
  Started := Now;
  ICMP := TIdICMPClient.Create(nil);
  try
    ICMP.Host := AHost;
    ICMP.ReceiveTimeout := 2000;
    ICMP.Ping();
    If  (ICMP.ReplyStatus.ReplyStatusType = rsEcho) Then
      Result:=MilliSecondsBetween(TDateTime.Now, Started);

  finally
    ICMP.Free;
  end;
end;

in timer

procedure TMainForm.UniTimer1Timer(Sender: TObject);
Var
   T : Integer;
   
begin
   T:=Ping2('1.1.1.1');
   if T>=0 then
      LPing.Caption:=T.ToString+ ' ms'
   Else
      LPing.Caption:= ' Error';
end;

 

and for program server as @Sherzod guide me we can use this code

Function UniServer(Var RetParams : Tstringlist):Integer;
begin
  With RetParams Do
     Begin
        Add('Memory Used:'+UniServerModule.ServerResources.MemoryUsed.ToString+'/'+UniServerModule.ServerResources.PeakMemoryUsed.ToString);
        Add('Process Memory Used:'+UniServerModule.ServerResources.ProcessMemoryUsed.ToString+'/'+UniServerModule.ServerResources.PeakProcessMemoryUsed.ToString);
        Add('USER Objects:'+UniServerModule.ServerResources.USERObjects.ToString+'/'+UniServerModule.ServerResources.PeakUSERObjects.ToString);
        Add('GDI Objects:'+UniServerModule.ServerResources.GDIObjects.ToString+'/'+UniServerModule.ServerResources.PeakGDIObjects.ToString);
        Add('CPU Usage:'+FloatToStr(UniServerModule.ServerResources.CPUUsage)+'/'+FloatToStr(UniServerModule.ServerResources.PeakCPUUsage));
        Add('Handles:'+UniServerModule.ServerResources.Handles.ToString+'/'+UniServerModule.ServerResources.PeakHandles.ToString);
     End;
end;

 

Great !

Thx

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