0
我创建一个套接字连接,并使用一个线程通过套接字连续发送数据使用下面的代码的数据(德尔福):TCP套接字停止发送
if (FSocketSession.Connected) and (Msg.JSONEvent <> '') then
begin
FSocketSession.Send(TEncoding.UTF8.GetBytes(Msg.JSONEvent))
Msg.Free;
end
else
begin
FSocketSession.Connect;
end;
这是FSocketSession.Send电话:
function TSocketSession.Send(const ADataToSend: TBytes): Integer;
var
Stopwatch: TStopwatch;
SentBytes: Integer;
const
SleepTimeMS = 10;
begin
SiMain.TrackMethod(Self, 'Send');
{$IFDEF USE_SSL}
if FIsSSL then
begin
SiMain.LogInteger('SslState', Ord(FSocket.SslState));
end;
{$ENDIF}
FDataSent := False;
if FSocket.State = wsConnected then
begin
SentBytes := FSocket.Send(@(ADataToSend[Low(ADataToSend)]), Length(ADataToSend));
SiMain.LogInteger('SentBytes', SentBytes);
Stopwatch := TStopwatch.StartNew;
end;
while (FSocket.State = wsConnected) and (not FDataSent) do
begin
FSocket.MessagePump;
Sleep(SleepTimeMS);
if (Stopwatch.ElapsedMilliseconds >= FTimeout) then
begin
FError := CErrorCommTimeout;
break;
end;
end;
Result := FError;
end;
我注意到,在某些电脑,插座简单地停止的一段时间内(通常它发生约1或2分钟后),并在其上运行,没有任何问题的其他电脑发送数据。有没有人看到可能导致这种情况发生的代码?如果需要,我可以提供更多信息。