|
-
Mar 16th, 2004, 03:57 PM
#1
Thread Starter
yay gay
Sending files thru Sockets
Well i have the following code to send a file:
Code:
FileStream fs = new FileStream(this._fileName, FileMode.Open);
byte[] buffer = new byte[4096];
int bufferLength = buffer.Length;
while(fs.Read(buffer, 0, buffer.Length) > 0) {
e.SocketClient.Send(buffer);
}
It sends the file, but the received file is completly screwed up. It looks like it just repeats the first chunk of data sent all over the file. I tried puting a Thread.Sleep(1000) meaning it would wait 1second between each buffer send and it worked wonderfully. The only problem is it takes forever to send files. What do you think about it? Did I forget something?
\m/  \m/
-
Mar 16th, 2004, 06:12 PM
#2
Frenzied Member
Wow, that seems a little strange. How about a do events instead of sleep?
-
Mar 18th, 2004, 05:00 PM
#3
Thread Starter
yay gay
I think the thing here is that my program has a loop of Sends() that will send my small parts the whole file. My socket class uses async delegates to achieve this without blocking the code. Obviously my Send() loop will be faster than my socket class to process and actually send all the sockets and that's why i think they only are correctly sent when i put a Thread.Sleep(1000).
Anyone have seen a .NET class around to send WHOLE files over the internet so I can see how the experts do it?
\m/  \m/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|