[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Robert Hill

1/14/2003 2:35:00 PM

I am very new to TCP/IP and I am challenged with writing
a .NET component for listening and sending files accross
our network. I have looked at the Listener and Client
code example and that works just fine for the short string
they send. I am trying to send a 128K XML file and I can
only get approx 8K to be received. Is there an issue with
packet size? How do I get the entire file from one
machine to the other using .NET and TCP/IP?

Thanks,
Robert
1 Answer

(Ping Zheng)

1/15/2003 9:41:00 AM

0

Hi,

My understanding of this problem is: You want to read a file from other
comptuer. In fact, you can use the classes of file operation provided by
.NET directly, they are more simple in this situation. Because you are
needed to organize the data package as the file by yourself if you used the
TCP/IP classes.

I listed the classes for your reference:
System.IO.File
System.IO.FileStream: it is used to open the file
System.IO.BinaryReader: it is used to read the file content
System.IO.BinaryWriter: it is used to write the file

In addition, I listed the code snip for your reference:

..
bool bRetVal = false;
if(File.Exists(srcfile) && Directory.Exists(destdir))
{
FileStream fs = new FileStream(srcfile, FileMode.Open);
BinaryReader r = new BinaryReader(fs);

//construct the destination file name
string destFile = null;
destFile = destdir;
destFile +="\\";
destFile += srcfile;
//create the file stream
//FileMode.Create means always create the file
FileStream fs1 = new FileStream(destFile, FileMode.Create);
BinaryWriter w = new BinaryWriter(fs1);

r.BaseStream.Seek(0,SeekOrigin.Begin); //set the file pointer to the
beginning
long filelen = r.BaseStream.Length;
long readlen = 0;
byte[] content = null;

while(readlen < filelen)
{
int tempcount = (int)(filelen-readlen);
if(tempcount > 100)
{
tempcount = 100;
}

content = r.ReadBytes(tempcount);

w.Write(content);
readlen += tempcount;
}

//close the read file handle
r.Close();
fs.Close();

//close the write file handle
w.Close();
fs1.Close();
bRetVal = true;
}
else
bRetVal = false;

return bRetVal;
}
}
}


This posting is provided "AS IS" with no warranties, and confers no rights.

George Zheng [MSFT]