Delphi - Indy客户端/服务器发送缓冲区

时间:2015-11-05 18:37:02

标签: delphi indy

我尝试将缓冲区从客户端发送到服务器...缓冲区已恢复,但在转换缓冲区时收到错误消息'数据错误' 在服务器端进入蒸汽

此外,我尝试将该缓冲区作为 Stream 发送,但我在服务器端收到错误消息内存不足

客户端:

procedure TAudio.Buffer(Sender: TObject; Data: Pointer; Size: Integer);
var
  Stream: TMemoryStream;
  Buff:string;
begin
  Move(Data^, ACMC.BufferIn^, Size);

  if AConn.Client.Connected then begin
    Stream := TMemoryStream.Create;
    Stream.WriteBuffer(ACMC.BufferOut^, ACMC.Convert);
    Stream.Position := 0;
    Buff := ZCompressStreamToString(Stream);
    AConn.Client.IOHandler.WriteLn(Buff);
    Stream.Free;
    Writeln('sent');
   end;
end;

服务器线程:

  try
    List := MainForm.idtcpsrvrMain.Contexts.LockList;
    try
      if List.IndexOf(Ctx) <> -1 then
      begin
        TMainContext(Ctx).Queue.Add(EncryptStr('AUDIO|2|'+BYTES));
        Stream:
         Buffer := TMainContext(Ctx).Connection.IOHandler.ReadLn;
         mStream := TMemoryStream.Create;
         try
          ZDecompressStringToStream(Buffer,mStream);
          mStream.Position := 0;
          SetLength(Buffer,mStream.Size);
          mStream.ReadBuffer(pointer(Buffer)^,mStream.Size);
          SendMessage(hLstbox,LB_ADDSTRING,0,lparam(Buffer));
          iList := SendMessage(hLstbox,LB_GETCOUNT,0,0);
          SendMessage(hLstbox,LB_SETTOPINDEX,iList-1,0);
          ACMO.Play(Pointer(Buffer)^,Length(Buffer));
         finally
           mStream.Free;
         end;
          if NodesList.Items[index].TerminateAudioThreads then
          begin
            ..
            ..   
            Terminate;
          end
          else goto Stream;

注意:

ZCompressStreamToString &amp; ZDecompressStringToStream 函数在客户端进行测试,并且有效。

0 个答案:

没有答案