TRtcHttpServer Connections.

2018-06-17 18:57:14来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

 Author TRtcHttpServer Connections.
Steve Gill

02.09.2006 09:15:00
Registered user
I would like to display the number of current connections in the server's main window.  I have tried both the TotalConnectionCount and TotalServerConnectionCount methods in the Connect and Disconnect events.  They seem to show the correct count when clients connect, but the counts seem to be one too many when the clients disconnect.

As each client connects the count goes up.  However, the count seems do be one step behind on disconnects.  When there is only 1 client connected it shows 2 connections.  And when no clients are connected it shows 1 connection.


procedure TfrmMain.HttpServerConnect(Sender: TRtcConnection);
begin
   with Sender as TRtcConnection do
   begin
      edtConnections.IntValue := TotalConnectionCount;
   end;
end;

procedure TfrmMain.HttpServerDisconnect(Sender: TRtcConnection);
begin
   with Sender as TRtcConnection do
   begin
      edtConnections.IntValue := TotalConnectionCount;
   end;
end;


Is there anything else I need to do?

Regards,

SteveG
Danijel Tkalcec [RTC]

02.09.2006 14:11:31
Registered user
TotalConnectionCount is increased before the first event is called and decreased after the last event was executed, which means that you should use "TotalConnectionCount-1" from the OnDisconnect/OnDisconnecting event.

Btw .. there's no need to cast Sender to TRtcConnection, since it already is TRtcConnection. You should only cast it to TRtcDataServer if you need more infromation. 

Also, if your Server is MultiThreaded, you need to Sync() your events before accessing the GUI:
procedure TfrmMain.HttpServerConnect(Sender: TRtcConnection);
begin
  if not Sender.inMainThread then
    Sender.Sync(HttpServerConnect)
  else
    edtConnections.IntValue := Sender.TotalConnectionCount;
end;

procedure TfrmMain.HttpServerDisconnect(Sender: TRtcConnection);
begin
  if not Sender.inMainThread then
    Sender.Sync(HttpServerDisconnect)
  else
    edtConnections.IntValue := Sender.TotalConnectionCount-1;
end;

Best Regards,
Danijel Tkalcec
Steve Gill

04.09.2006 01:49:14
Registered user
Thanks Danijel.

> Btw .. there's no need to cast Sender to TRtcConnection, since 
> it already is TRtcConnection. You should only cast it to 
> TRtcDataServer if you need more infromation. 

Yeah, you're right.  Force of habit I guess.


> Also, if your Server is MultiThreaded, you need to Sync() your
> events before accessing the GUI:

Not multi-threaded but thanks for the code.

Regards,

SteveG

PS How do you do the "quoting" in forum messages?
Danijel Tkalcec [RTC]

04.09.2006 12:17:36
Registered user
This Forum has a few BBCode functions implemented:
To open source code block, use [code]
To close source code block, use [ /code] - remove the space after [ 

To insert URL Link, use [url http://mydomain/mylink]
To insert URL Link with your own text, 
use [url=http://mydomain/mylink]Mytext[/url]

To insert Image, use [img http://mydomain.com/imagefile.gif]
To insert Image with your own alt text,
use [img=http://mydomain/myfile.gif]Alt text[/img]

Best Regards,
Danjel Tkalcec
Steve Gill

05.09.2006 00:46:48
Registered user
Nice.  Thanks Danijel.

Regards,

SteveG
ISOFT, INC.

24.01.2007 16:26:38
Registered user
The above code in Delphi looks like this in BCB



void __fastcall TForm1::RtcHttpServer1Connect(TRtcConnection *Sender)
{
        if (Sender->inMainThread() == false)
        {
                Sender->Sync(&RtcHttpServer1Connect);
        }
        else
        {
                StatusBar1->SimpleText = "Total connections: " + AnsiString(Sender->TotalConnectionCount());
        }
}

void __fastcall TForm1::RtcHttpServer1Disconnect(TRtcConnection *Sender)
{
        if (Sender->inMainThread() == false)
        {
                Sender->Sync(&RtcHttpServer1Connect);
        }
        else
        {
                StatusBar1->SimpleText = "Total connections: " + AnsiString(Sender->TotalConnectionCount()-1);
        }
}



This is my first attempt at this - so I may not have done it exactly right.

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:用 RAD Studio 柏林版创建 IoT 应用程序

下一篇:Sessions