zoukankan      html  css  js  c++  java
  • datasnap 2010 心跳包,连接断开处理

    datasnap 2010 心跳包,连接断开处理
    procedure TMainForm.DSServer1Connect
    (DSConnectEventObject: TDSConnectEventObject);
    var
    // RowIndx: Integer;
    InVal: TCP_KeepAlive;
    Ret: DWORD;
    ClientConnection: TIdTCPConnection;
    begin
    EnterCriticalSection(CSConnect);
    try
    // 最大连接数量,验证来访者密码
    if (ConnectCount >= 500) or (DSConnectEventObject.ChannelInfo = nil) or
    (DSConnectEventObject.ConnectProperties[TDBXPropertyNames.UserName]
    <> 'sunstone') or (DSConnectEventObject.ConnectProperties
    [TDBXPropertyNames.Password] <> 'mypassword') then
    begin
    // ClientConnection.Disconnect;
    DSConnectEventObject.DbxConnection.Destroy;
    Exit;
    end
    else
    begin
    // 获取socket连接
    ClientConnection := TIdTCPConnection(DSConnectEventObject.ChannelInfo.Id);

    // 同IP连接频率控制
    // for RowIndx := ShowConnections.RowCount - 1 downto 1 do
    // begin
    // if AnsiPos(ClientConnection.Socket.Binding.PeerIP + ':',
    // ShowConnections.Cells[1, RowIndx]) > 0 then
    // begin
    // if SecondsBetween(Now,
    // StrToDateTimeDef(ShowConnections.Cells[4, RowIndx], Now)) >= 1 then
    // begin
    // Break;
    // end
    // else
    // begin
    // DSConnectEventObject.DbxConnection.Destroy;
    // Exit;
    // end;
    // end;
    // end;

    // 设置心跳包
    Ret := 0;
    InVal.OnOff := 1;
    InVal.KeepAliveTime := 4000;
    InVal.KeepAliveInterval := 1;
    if WSAIoctl(ClientConnection.Socket.Binding.Handle,
    IOC_IN or IOC_VENDOR or 4, @InVal, sizeof(TCP_KeepAlive),
    nil, 0, @Ret, nil, nil) = SOCKET_ERROR then
    begin
    DSConnectEventObject.DbxConnection.Destroy;
    Exit;
    end;

    // 建立网络异常断开事件
    ClientConnection.OnDisconnected := ClientDisconnectEvent;

    // 显示来访者信息
    inc(ConnectCount);
    ConnectInfo.Panels.Items[1].Text := IntToStr(ConnectCount);

    if Trim(ShowConnections.Cells[0, 1]) <> '' then
    ShowConnections.RowCount := ShowConnections.RowCount + 1;

    ShowConnections.Cells[0, ShowConnections.RowCount - 1] := IntToStr
    (DSConnectEventObject.ChannelInfo.Id);
    ShowConnections.Cells[1, ShowConnections.RowCount - 1] :=
    ClientConnection.Socket.Binding.PeerIP + ':' + IntToStr
    (ClientConnection.Socket.Binding.PeerPort);
    ShowConnections.Cells[2, ShowConnections.RowCount - 1] :=
    DSConnectEventObject.ConnectProperties[TDBXPropertyNames.UserName];
    ShowConnections.Cells[3, ShowConnections.RowCount - 1] :=
    DSConnectEventObject.ConnectProperties[TDBXPropertyNames.Password];
    ShowConnections.Cells[4, ShowConnections.RowCount - 1] := FormatDateTime
    ('yyyy-mm-dd hh:nn:ss', Now);
    end;
    finally
    LeaveCriticalSection(CSConnect);
    end;
    end;
     
  • 相关阅读:
    “fatal error: hdf5.h: 没有那个文件或目录”解决方法
    算法狗的机器学习基础
    统计:假设检验 T检验
    各种排序和数据结构算法收藏
    知乎好书--入门神经网络和机器学习
    机器学习中的数学(1)-回归(regression)、梯度下降(gradient descent)
    第八天 T3S04
    第七天 T3S03
    第六天T3S02
    T3S01
  • 原文地址:https://www.cnblogs.com/leonkin/p/2363707.html
Copyright © 2011-2022 走看看