程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> TRtcHttpServer Connections.,chttpserver

TRtcHttpServer Connections.,chttpserver

編輯:Delphi

TRtcHttpServer Connections.,chttpserver


 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.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved