Results 1 to 3 of 3

Thread: Sending files thru Sockets

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    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/

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Wow, that seems a little strange. How about a do events instead of sleep?

  3. #3

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    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
  •  



Click Here to Expand Forum to Full Width