Sending big file over TCP

Spiro

Member
Joined
Feb 5, 2003
Messages
15
Location
Croatia
With big file i mean file biger then RecieveBuffer.
Code:
Dim nStream As NetworkStream
If nStream.DataAvailable = True Then
Dim recbuf(client.ReceiveBufferSize-1) As Byte    
nStream.Read(recbuf, 0, client.ReceiveBufferSize)
end if

Now, RecBuf should hold first 8192 bytes of data. Instead, it holds 7k of valid data and rest is full of 0.
When i read 20 times and then write everything to file i got invalid file: 7k valid data, 1k of 00 and so on...
How should i solve this?
 
It sounds to me like you should be writing what you receive to the file every time you receive it, as the receive buffer will only hold what it is dimensioned as. It is best to write continuously like this, otherwise you can end up holding more data than you need to in memory.
 
Maybe i should, but it doesnt solve my problem. In the file will be data from RecBuf byte array, with some data and zeros at the end. If i try to append data zeros will remain.
 
Back
Top