TCP Keep Alive on idHttpServer (server) and wininet (client)

前端 未结 1 847
生来不讨喜
生来不讨喜 2020-12-19 13:25

I have a webserver application developed using idHttpServer. When a client connects do my webserver and, for some unknown reason, got disconnect (not a gracefully disconnect

相关标签:
1条回答
  • 2020-12-19 13:57

    If you are using an up-to-date Indy 10 release, then you can use the TIdSocketHandle.SetKeepAliveValues() method:

    procedure SetKeepAliveValues(const AEnabled: Boolean; const ATimeMS, AInterval: Integer);
    

    For example:

    procedure TForm1.IdHTTPServer1Connect(AContext: TIdContext);
    begin
      // send a keep-alive every 1 second after
      // 5 seconds of inactivity has been detected
      AContext.Binding.SetKeepAliveValues(True, 5000, 1000);
    end;
    

    Note that the ATimeMS and AInterval parameters are only supported on Win2K and later.

    Otherwise, use the TIdSocketHandle.SetSockOpt() method directly to enable the TCP/IP SO_KEEPALIVE option manually:

    procedure TIdSocketHandle.SetSockOpt(ALevel: TIdSocketOptionLevel; AOptName: TIdSocketOption; AOptVal: Integer);
    

    For example:

    procedure TForm1.IdHTTPServer1Connect(AContext: TIdContext);
    begin
      AContext.Binding.SetSockOpt(Id_SOL_SOCKET, Id_SO_KEEPALIVE, 1);
    end;
    
    0 讨论(0)
提交回复
热议问题