zoukankan      html  css  js  c++  java
  • 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;

  • 相关阅读:
    继续对dubbo源代码进行maven builder
    Oracle操作XML各种场景介绍
    GitHub上的SliddingMenu滑动过程中卡顿问题的解决的方法
    [leetcode] Reverse Words in a String [1]
    UI标签库专题五:JEECG智能开发平台 Tabs(选项卡父标签)
    JAVA的一次编译,到处执行,你知道多少?
    设计模式学习--------12.代理模式学习
    P3573 [POI2014]RAJ-Rally
    2019-2-21-PowerShell-通过-WMI-获取补丁
    2019-2-21-PowerShell-通过-WMI-获取补丁
  • 原文地址:https://www.cnblogs.com/fhweixin/p/13743015.html
Copyright © 2011-2022 走看看