9999999999 Me(9分)

  • 主题发起人 主题发起人 Mclkings
  • 开始时间 开始时间
M

Mclkings

Unregistered / Unconfirmed
GUEST, unregistred user!
当我用内存流压缩数据后~~~

服务器端返回数据时,客户端对服务器端的数据不能进行正确的解压操作~~

请问:应该如何进行操作~~.怪~

我把这个函数单独做了一个应用程序,就可以传输没有事情的,可是做到我现在的服务器里

就不行.很是郁闷,所以想请教大家,在这方面哪里容易出问题~~>
 
我也郁闷/。。。。http://www.delphibbs.com/delphibbs/dispq.asp?lid=3491075
 
可能是和其他的代码有冲突或者被屏蔽了?
 
//服务器端压缩
procedure CompressData(var CompressedStream: TMemoryStream;
const CompressionLevel: TCompressionLevel);
var
SourceStream: TCompressionStream;
DestStream: TMemoryStream;
Count: Integer;
Begin
Count := CompressedStream.Size;
DestStream := TMemoryStream.Create;
SourceStream:=TCompressionStream.Create(CompressionLevel, DestStream);
Try
CompressedStream.SaveToStream(SourceStream);
//将原始流进行压缩, DestStream中保存着压缩后的流
SourceStream.Free;
CompressedStream.Clear;
//写入原始流的尺寸
CompressedStream.WriteBuffer(Count, SizeOf(Count));
//写入经过压缩的流
CompressedStream.CopyFrom(DestStream, 0);
finally
DestStream.Free;
end;
end;

//客户端解压
procedure UnCompressData(var CompressedStream: TMemoryStream);
var
SourceStream: TDecompressionStream;
DestStream: TMemoryStream;
Buffer: PChar;
Count: integer;
Begin
CompressedStream.Position:=0;
CompressedStream.ReadBuffer(Count, SizeOf(Count));
GetMem(Buffer, Count);
DestStream := TMemoryStream.Create;
SourceStream := TDecompressionStream.Create(CompressedStream);
Try
SourceStream.ReadBuffer(Buffer^, Count);
DestStream.WriteBuffer(Buffer^, Count);
SourceStream.Free;
DestStream.Position := 0;//复位流指针
CompressedStream.LoadFromStream(DestStream);
finally
FreeMem(Buffer);
DestStream.Free;
end;
end;

//服务器端使用时
ms := TMemoryStream.Create;
ms.Position := 0;
CompressData(ms, clFastest);
ms.Free;
//客户端使用时
ms := TMemoryStream.Create;
ms.Position := 0;
UnCompressData(ms);
ms.Free;

我这样用N长时间了都没问题的
 
am2001
你是用什么来传输的~~?/
winsock 单元
Indy 组件
还是Delphi的TCustWinsocket啊?
你是用的哪个啊?????
 
后退
顶部