重贴
// 用TIdTCPClient发送
procedure Send(Stream: TMemoryStream);
var
DataSize: Integer;
begin
...
Stream.Position := 0;
// 将流的指针指向启始位置
DataSize := Stream.Size;
// 取命令数据长度
IdTCPClient.WriteStream(Stream, true, true, DataSize);
...
end;
// 用TIdTCPServer的OnExecute事件侦听并接收
procedure TSocketModule.IdTCPServerExecute(AThread: TIdPeerThread);
var
Stream: TMemoryStream;
begin
Stream := TMemoryStream.Create;
AThread.Connection.ReadStream(Stream);
// 等待,如果有控制台发送来的数据就接收
Stream.Position := 0;
// 置流的指针指向开始
...
AThread.Connection.WriteStream(Stream, true, true, DataSize);
// 发送流到到客户端
...
end;