如何确保以 TTetheringAppProfile.SendStream 发送的消息正确传递?

How to ensure that messages sent with TTetheringAppProfile.SendStream were delivered properly?

我有一个简单的移动应用程序,可以拍摄一系列照片并通过 SendStream() 将其发送到连接的配置文件。

myTetherAppProfile.SendStream(myTetherManager.RemoteProfiles[idConnected],
                              'ImageData',
                              bmpStreamData);

这里出现的问题是接收器应用程序没有根据连接强度获取所有图像流(接收器应用程序上没有触发 ResourceReceived 事件)。

如果我收到投递失败的回复,这没有问题。但是我不明白这个 (SendStream() returns "True")

除了实现 "please answer with another message if you received my image" 功能之外,还有没有可能在连接不良的情况下实现稳定的传输?还是 App-Tethering 默认设计为有损?

此外,在处理大量图像后,我有时会遇到 "connection reset by peer" 错误。 (我不确定这个错误是否与实际问题有关,所以我更喜欢发布它。)

查看System.Tether.AppProfile(XE8版本)的相关代码,好像是个bug。请参阅下面我的内联评论。请报告给https://quality.embarcadero.com

function TTetheringAppProfile.SendStream(const AProfile: TTetheringProfileInfo; const Description: string;
  const AStream: TStream): Boolean;
var
  LProfileInfo: TTetheringProfileInfo;
  LConnection: TTetheringConnection;
  LCommand: TTetheringCommand;
begin
  if not FindProfile(AProfile.ProfileIdentifier, LProfileInfo) then
    raise ETetheringException.CreateFmt(SNoProfile, [AProfile.ProfileIdentifier]);
  CheckProfileIsConnected(AProfile);
  LConnection := GetConnectionTo(AProfile);
  TMonitor.Enter(LConnection);
  try
    LCommand := LConnection.Protocol.SendCommandWithResponse(SendStreamCommand, Version, Description);
    if LCommand.Command = SendStreamOkResponse then
    begin
      Result := LConnection.Protocol.TransferStream(AStream);
      if Result then
      begin    <-- Result here is guaranteed to be True
        LCommand := LConnection.Protocol.ReceiveCommand;
        if LCommand.Command = SendStreamContentOKResponse then
          Result := True;  <-- Sets Result to True if succeeds, 
              <-- but nothing to set Result to False if call failed.
      end;
    end
    else
      Result := False;
  finally
    TMonitor.Exit(LConnection);
  end;
end;