File sent only partially

  • Thread starter Thread starter Piotrekk
  • Start date Start date
P

Piotrekk

Hi
I have a question.
Why file, that i wanna send is sent only partially.
When i wanna send 4xx kb only 266 is sent.
Thanks for your help
PK

Here is the code:

if (Client.Connected)
{
String line = null;
file = new StreamReader(sfName);
fileLength = file.BaseStream.Length;
Client.Client.Send(fName, 0, fName.Length,
SocketFlags.None);


mylegth = fileLength / 100;
long i = 0;
this.smoothprogressBar1.Value = 0;

while ((line = file.ReadLine()) != null)
{
i +=
Client.Client.Send(ASCIIEncoding.ASCII.GetBytes(line));
this.smoothprogressBar1.Value = (int) ((i *
100)/ fileLength);
}

file.Close();
Client.Close();
}
 
Piotrekk said:
I have a question.
Why file, that i wanna send is sent only partially.
When i wanna send 4xx kb only 266 is sent.

Well, the first problem is that you're reading the file as a text file
with an ASCII encoding. If the file contains any non-ASCII data, you'll
be losing it. Why not just send it as binary data in the first place?

The second problem I can see is that you're not sending the line
terminators.

Beyond that, it's somewhat hard to tell, particularly as we don't know
the type of "Client".

Could you post a short but complete example which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details on
what I mean by that.

Jon
 
Back
Top