TRtcHttpServer Connections.

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

转载于:https://www.cnblogs.com/liangchua/p/6594497.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值