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;
     
  • 相关阅读:
    环境是如何建立的 启动文件有什么
    环境中存储的是什么
    串行 并行 异步 同步
    TPC-H is a Decision Support Benchmark
    进程通信类型 管道是Linux支持的最初Unix IPC形式之一 命名管道 匿名管道
    删除环境变量
    14.3.2.2 autocommit, Commit, and Rollback 自动提交 提交和回滚
    14.3.2.2 autocommit, Commit, and Rollback 自动提交 提交和回滚
    14.3.2.1 Transaction Isolation Levels 事务隔离级别
    14.3.2.1 Transaction Isolation Levels 事务隔离级别
  • 原文地址:https://www.cnblogs.com/leonkin/p/2363707.html
Copyright © 2011-2022 走看看