日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

datasnap 如何监控客户端的连接情况

發布時間:2025/6/17 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 datasnap 如何监控客户端的连接情况 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

如果客戶端是TCP/IP是短連接的情況就沒有必要了。

?

type
pClientConns = ^TClientConns; // 客戶連接
TClientConns = record
clientid: integer;
ip: string;
port: string;
logintime: TDateTime;
end;

type
G_ClientConnects: TDictionary<TIdTCPConnection, pClientConns>; // 客戶端連接字典

procedure TServerContainer1.DSTCPServerTransport1Connect
(Event: TDSTCPConnectEventObject);
var
p: pClientConns;
begin
try
if G_ConnnectCount >= G_MaxConnNum then
begin
LogInfo('已超過系統授權的客戶連接數');
TIdTCPConnection(Event.Connection).Disconnect;
exit;
end;
InterlockedIncrement(G_ConnnectCount);
New(p);
if Assigned(p) then
begin
p^.clientid := Event.Channel.ChannelInfo.Id;
p^.ip := Event.Channel.ChannelInfo.ClientInfo.IpAddress;
p^.port := Event.Channel.ChannelInfo.ClientInfo.ClientPort;
p^.logintime := Now;
G_ClientConnects.Add(TIdTCPConnection(Event.Connection), p);
PostMessage(Application.MainForm.Handle, WM_ADDUSER, wParam(p),
lParam(TIdTCPConnection(Event.Connection)));
end;
except
exit;
end;
end;

procedure TServerContainer1.DSTCPServerTransport1Disconnect
(Event: TDSTCPDisconnectEventObject);
var
p: pClientConns;
begin
try
if G_ConnnectCount >= 1 then
InterlockedDecrement(GlobalVar.G_ConnnectCount);
p := G_ClientConnects.Items[TIdTCPConnection(Event.Connection)];
if Assigned(p) then
begin
SendMessage(Application.MainForm.Handle, WM_DELUSER, wParam(p), 0);
G_ClientConnects.Remove(TIdTCPConnection(Event.Connection));
end;
except
exit;
end;
end;

procedure Tf_MainForm.AddUser(var msg: TMessage);
var
p: pClientConns;
begin
try
Label4.Caption := IntToStr(G_ConnnectCount);
p := pClientConns(msg.WParam);
if Assigned(p) then
begin
ClientDataSet1.Append;
ClientDataSet1.FieldByName('id').AsInteger := p^.clientid;
ClientDataSet1.FieldByName('ip').AsString := p^.ip;
ClientDataSet1.FieldByName('port').AsString := p^.port;
ClientDataSet1.FieldByName('time').AsDateTime := p^.logintime;
ClientDataSet1.FieldByName('conn').AsInteger := msg.LParam;
ClientDataSet1.Post;
end;
except
on E: Exception do
begin
LogInfo('Tf_MainForm.AddUser---' + E.Message);
exit;
end;
end;
end;

procedure Tf_MainForm.DelUser(var msg: TMessage);
var
p: pClientConns;
begin
try
Label4.Caption := IntToStr(G_ConnnectCount);
p := pClientConns(msg.WParam);
if Assigned(p) then
begin
if ClientDataSet1.FindKey([p^.clientid]) then
ClientDataSet1.Delete;
Dispose(p);
end;
except
on E: Exception do
begin
LogInfo('Tf_MainForm.DelUser---' + E.Message);
exit;
end;
end;
end;

?

轉載于:https://www.cnblogs.com/hnxxcxg/archive/2013/03/07/2947462.html

總結

以上是生活随笔為你收集整理的datasnap 如何监控客户端的连接情况的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。