#1 2014-12-23 07:34:32

win2014
Member
Registered: 2014-06-10
Posts: 31

TCrtSocket.ReceiveTimeout problem

tcp := TCrtSocket.Open(RawByteString(aServer), RawByteString(IntToStr(FPort)));
  if tcp <> nil then begin
    try
      tcp.ReceiveTimeout := 5 * 1000;
      tcp.CreateSockIn;
      tcp.CreateSockOut;
      Writeln(tcp.SockOut^, aCommand);
      aRawData := tcp.SockReceiveString; // Never come back sometimes
      Result := string(aRawData).Trim;
    except
      on E: Exception do
        LogException(E, Format('Command: %s - TWhoisQuery.SendCommand()', [aCommand]));
    end;
    FreeAndNil(tcp);
  end;

Up codes, SockReceiveString with comment has a problem, it never come back sometimes.

Offline

#2 2014-12-23 07:37:25

win2014
Member
Registered: 2014-06-10
Posts: 31

Re: TCrtSocket.ReceiveTimeout problem

Is there a bug in SO_RCVTIMEO?

Offline

#3 2014-12-27 11:51:22

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,237
Website

Re: TCrtSocket.ReceiveTimeout problem

In fact, we never use SockReceiveString method in our code base.
This method sounds unsafe to use.

You should better call CreateSockIn, then use Readln(SockIn,s) to read a line from the opened socket.
Or call directly the SockRecvLn() method or TCrtSocket.TrySockRecv() if you do not call CreateSockIn.

Offline

Board footer

Powered by FluxBB