C
C#2y ago
Lander

✅ Recieve less than transmitting in network stream

Hello there, I'm trying to implement a FTP server and I got troubles with the network stream Whenever I transmit a 4669 file, I recieve only 3779 and it's sending 0 which as it says marks the end of the data. The headers I sent indicate the file's size so I know exactly how much to expect and I got the conditions for it. I have tried almost everything I could think of. Here is the code for the server:
while(totalRead < size)
{
read = reader.Read(buffer, 0, buffer.Length);
if (read == 0)
{
Console.WriteLine("read is empty {0}", read);
break;
}


totalRead += read;
if(read < buffer.Length)
{
Array.Resize(ref buffer, read);
}
f.Write(buffer,0, buffer.Length);
f.Seek(totalRead, SeekOrigin.Begin);
}
reader.Close();
while(totalRead < size)
{
read = reader.Read(buffer, 0, buffer.Length);
if (read == 0)
{
Console.WriteLine("read is empty {0}", read);
break;
}


totalRead += read;
if(read < buffer.Length)
{
Array.Resize(ref buffer, read);
}
f.Write(buffer,0, buffer.Length);
f.Seek(totalRead, SeekOrigin.Begin);
}
reader.Close();
Here is the code of the client:
while (totalRead < fSz)
{
read = fs.Read(buf, 0, buf.Length);
if (read == 0)
break;
totalRead += read;
if(read < buf.Length)
{
Array.Resize(ref buf, read);
}

stream.Write(buf, 0, buf.Length);

}
fs.Close();

stream.Close();
while (totalRead < fSz)
{
read = fs.Read(buf, 0, buf.Length);
if (read == 0)
break;
totalRead += read;
if(read < buf.Length)
{
Array.Resize(ref buf, read);
}

stream.Write(buf, 0, buf.Length);

}
fs.Close();

stream.Close();
in both
stream
stream
is an instace of Network stream created with the underlying socket of TcpClient. I would appreciate any help. Thank you.
3 Replies
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Lander
LanderOP2y ago
Still active
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server