Jump to content

Multipart - networked downloader

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
17 replies to this topic

#1
sp3tsnaz

sp3tsnaz

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
i want to program a downloader which works for slow networks. for example if i and a friend of mine are connected through a LAN .. i would want my downloader to download 1-50 % of xyz.file and my friend would download 51-100% of xyz.file ... (where xyz.file is any file to be downloaded from a website) . In the next stage the downloader would merge the files together to produce the original file.. i wish to program this thing using c# . Any help is welcome .. Please also tell me which classes/interfaces to study for this project of mine .. any kick-start code is also welcome ..

Regards
M Mohsin Ali

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I'm not sure how I'd go about this, but how would this help? It won't change the throughput into your LAN.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
ArekBulski

ArekBulski

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,376 posts
Well, downloading files from a web pages goes through WebRequest and WebResponse. But I never heard of downloading a file, partially and not from beginning. I imagine that if you can resume a download, then you could as well start it from some other point. But I do not have enough knowledge of how they work, I am sorry.

Splitting or joining files would be just few lines of code. That is the easy part, of course. Using FileStream classes would do it easily. ;)

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Some download managers can do things like that.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
sp3tsnaz

sp3tsnaz

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts

WingedPanther said:

I'm not sure how I'd go about this, but how would this help? It won't change the throughput into your LAN.
this problem is not related to the throughput of LAN .. it will benefit quick downloading of files on a network lets say an institutional network like ours which does not allow downloading files > 50 mb .. call it parallel downloading ..

#6
sp3tsnaz

sp3tsnaz

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts

ArekBulski said:

Well, downloading files from a web pages goes through WebRequest and WebResponse. But I never heard of downloading a file, partially and not from beginning. I imagine that if you can resume a download, then you could as well start it from some other point. But I do not have enough knowledge of how they work, I am sorry.

Splitting or joining files would be just few lines of code. That is the easy part, of course. Using FileStream classes would do it easily. ;)
could you please specify more about the filestream classes .. an example would be of much help . thankyou

#7
sp3tsnaz

sp3tsnaz

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts

ArekBulski said:

Well, downloading files from a web pages goes through WebRequest and WebResponse. But I never heard of downloading a file, partially and not from beginning. I imagine that if you can resume a download, then you could as well start it from some other point. But I do not have enough knowledge of how they work, I am sorry.

Splitting or joining files would be just few lines of code. That is the easy part, of course. Using FileStream classes would do it easily. ;)
man you are the god :D webrequest and webresponse classes , i just explored .. i went through Httpwebrequest class... it has a method AddRange (int , int);
which does the job .. im posting the sample code i grabbed from msdn .. let me know if im going in the rigth direction or not .. thankyou loads ..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a New 'HttpWebRequest' object .
            HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("some web address");
            myHttpWebRequest.AddRange(50, 150);
            // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
            HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
            // Display the contents of the page to the console.
            Stream streamResponse = myHttpWebResponse.GetResponseStream();
            StreamReader streamRead = new StreamReader(streamResponse);
            Char[] readBuffer = new Char[256];
            int count = streamRead.Read(readBuffer, 0, 256);
            Console.WriteLine("\nThe HTML contents of the page from 50th to 150 charaters are :\n  ");
            while (count > 0)
            {
                String outputData = new String(readBuffer, 0, count);
                Console.WriteLine(outputData);
                count = streamRead.Read(readBuffer, 0, 256);
            }
            // Release the response object resources.
            streamRead.Close();
            streamResponse.Close();
            myHttpWebResponse.Close();
            Console.In.Read();
        }
    }
}


#8
sp3tsnaz

sp3tsnaz

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
msdn[dot]microsoft[dot]com[slash]en-us[slash]library[slash]aa329614(VS.71)[dot]aspx


sorry but i cant post the links .. im not permitted to.. replace [dot] with '.' in the above link :p and slash with /

Edited by sp3tsnaz, 03 September 2009 - 08:05 AM.


#9
ArekBulski

ArekBulski

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,376 posts
Lol, removing "www." would do just fine. No need to turn it into a l33t code.

msdn.microsoft.com/en-us/library/aa329614(VS.71).aspx

So this is the method. I cannot say what it does, sorry.
HttpWebRequest.AddRange Method (Int32)

#10
ArekBulski

ArekBulski

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,376 posts
There you go, sp3tznaz. As you requested, a little elaboration about FileStream class. The second one is pretty neat IMO. :)
http://forum.codecal...ream-class.html
http://forum.codecal...le-methods.html

#11
sp3tsnaz

sp3tsnaz

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
well !! i explored.. this Httpwebrequest is basically a class for Http protocol .. it doesnt have anything to do with downloading a file .. :(

#12
ArekBulski

ArekBulski

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,376 posts
Well, WebRequest is indeed for downloading web pages, so I think it can also download files the same way, through http:// . You are on the right path, just dig deeper.

Never give up...never give up! :)