设为首页 加入收藏

TOP

TRtcHttpServer Connections.(一)
2017-10-10 12:03:38 】 浏览:5876
Tags:TRtcHttpServer Connections.

 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]M
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Sessions 下一篇[笔记] 升級到 Delphi 10.2 Tokyo..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目