I measure it simply by logging the size of the TMemoryStream to be sent and the length of the NSData that has been received.
I can't really know what the extra data looks like as it's difficult to check it with large data.
For smaller TMemoryStreams I don't really have any problems, but with the very large data, it becomes problematic.
I end all my data "packets" with a specific string looking like this: <packetEnd>
and when I extract a substring of my total data packet the very last part of the packet is actually ending with <packetEnd>
and when I extract all data from index 0 up until the beginning of my file-data, everything is OK as well, starting with <packetStart> + some extra human-readable text and finally a ':' character followed by the file-data.
so everything seems to be OK, but still, too much data in it somewhere.
I have checked the size of the file on the server, and all attributes are correct.
So I don't really know whats going on here.
EDIT:
Here is my sending code:
procedure THoster.SendData(aData: TMemoryStream; AAddress: string);
var i, u: integer;
sendIndex: word;
idb: TIdBytes;
ctx : TIdContext;
begin
aData.Position := 0;
ReadTIdBytesFromStream(aData,idb,aData.Size,0);
with fTCP.Contexts.LockList do
begin
for i := 0 to Count -1 do
begin
ctx := TIdContext(Items[i]);
if AAddress <> '' then
begin
if ctx.Binding.PeerIP = AAddress then
begin
ctx.Connection.IOHandler.Write(idb, aData.Size, 0);
break;
end;
end
else ctx.Connection.IOHandler.Write(idb, aData.Size, 0);
end;
end;
end;