Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » knowing download speed and ProgressIndicator
knowing download speed and ProgressIndicator [message #16918] Mon, 21 July 2008 07:24 Go to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

hello again

i want to make a function that download files and also shows the download speed and shows the progress in a progress bar .... and also dont make the program stop Very Happy ( i mean multithreading )

now i can download files using

HttpClient client;
String url = attachments.GetData();
client.URL ( url );
String content;
content = client.ExecuteRedirect ( HttpClient::DEFAULT_MAX_REDIRECT, HttpClient::DEFAULT_RETRIES);
SaveFile ( "file" + FormatInt ( file_num ), content );


and i can open it in a new thread but now i want to show download speed and progress bar

and i want the progress bar to be ProgressIndecatior

thanks in advance and i am sorry for my many questions

Re: knowing download speed and ProgressIndicator [message #16949 is a reply to message #16918] Tue, 22 July 2008 17:32 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

why no one answered me ??
Re: knowing download speed and ProgressIndicator [message #16950 is a reply to message #16918] Tue, 22 July 2008 17:44 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
Simplest way (do this in the main thread):
Progress progress("Downloading file...");
HttpClient client;
String url = attachments.GetData();
client.URL ( url );
String content;
content = client.ExecuteRedirect ( HttpClient::DEFAULT_MAX_REDIRECT, HttpClient::DEFAULT_RETRIES, progress);
SaveFile ( "file" + FormatInt ( file_num ), content );
Re: knowing download speed and ProgressIndicator [message #16953 is a reply to message #16950] Tue, 22 July 2008 21:11 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

no ..... i know that

but i want to do more than one download a time and also know the download speed
Re: knowing download speed and ProgressIndicator [message #16956 is a reply to message #16953] Wed, 23 July 2008 10:20 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11991
Registered: November 2005
Ultimate Member
TeCNoYoTTa wrote on Tue, 22 July 2008 15:11

no ..... i know that

but i want to do more than one download a time and also know the download speed


The you have to add some

bool Method(int, int)

to your class and direct the callback there.

Mirek
Re: knowing download speed and ProgressIndicator [message #16960 is a reply to message #16956] Wed, 23 July 2008 12:59 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

i am sorry .....but please more explanation .....i am sorry

i will try and also wait for more explanation
Re: knowing download speed and ProgressIndicator [message #16961 is a reply to message #16960] Wed, 23 July 2008 13:05 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

i mean that this function
content = client.ExecuteRedirect ( HttpClient::DEFAULT_MAX_REDIRECT, HttpClient::DEFAULT_RETRIES);

download all the file once

so i want to know if there is other function or another way
Re: knowing download speed and ProgressIndicator [message #16962 is a reply to message #16918] Wed, 23 July 2008 13:41 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 797
Registered: November 2005
Location: Czech Republic - Praha
Contributor

Run new thread/instance of HttpClient for every URL you want to download together.

Create your own progress indicator with "bool MethodToGatherData(int, int)" in it.

Set this method as callback to every HttpClient during ExecuteRedirect call.

In that method find out a way to gather multiple data from different threads, calculate some nice numbers out of them, and show them as progress bar.

No source code this time, I'm too new into this topic to write it from head, and I have to work on different things. I think that's the reason for slow answers from others too, while you are free to ask, others are free to (not) answer, as their free time and skill allows them. If you want to learn C++,U++ and do your own application, just study hard and have patience (and keep asking, but also keep searching for answer on your own). If you want the app done fast, pay Mirek or some skilled other UPP developer. Smile
Re: knowing download speed and ProgressIndicator [message #17157 is a reply to message #16962] Thu, 31 July 2008 20:22 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

thanks all

i did this but there is an error

void Download_Manager_Window::progress_indecator(int x, int all)
{
	static int timer = 0;
	static int data = 0;
	progress_bar.Set(x,all);
	timer = clock() - timer;
	data = x - data;
	label_DownloadSpeed.SetText(DblStr((data/timer) * 1.0 ) + " KB/S");
	
	timer = clock();
	data = x;
}
void Download_Manager_Window::Download_File(String link)
{
	client.URL(link);
	client.Execute(THISBACK( progress_indecator ));
}


this is the error
D:\Program Files\MyApps\CISL\main.cpp:57: error: 'progress_indecator' is not a member of 'Upp::TopWindow'

[Updated on: Thu, 31 July 2008 20:25]

Report message to a moderator

Re: knowing download speed and ProgressIndicator [message #17161 is a reply to message #17157] Fri, 01 August 2008 08:41 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11991
Registered: November 2005
Ultimate Member
You need to add

struct Download_Manager_Window {
....
     typedef Download_Manager_Window CLASSNAME;
....
};


Mirek
Re: knowing download speed and ProgressIndicator [message #17168 is a reply to message #17161] Fri, 01 August 2008 09:17 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

thanks

i tried what you said but there still errors this is the code

void Download_Manager_Window::progress_indecator(int x, int all)
{
	static int timer = 0;
	static int data = 0;
	progress_bar.Set(x,all);
	timer = clock() - timer;
	data = x - data;
	label_DownloadSpeed.SetText(DblStr((data/timer) * 1.0 ) + " KB/S");
	
	timer = clock();
	data = x;
}
void Download_Manager_Window::Download_File(String link)
{
	client.URL(link);
	client.ExecuteRedirect(HttpClient::DEFAULT_MAX_REDIRECT,HttpClient::DEFAULT_RETRIES,THISBACK( progress_indecator ));
}


and this is the error

D:\Program Files\MyApps\CISL\main.cpp: In member function 'void Download_Manager_Window::Download_File(Upp::String)':
D:\Program Files\MyApps\CISL\main.cpp:60: error: no matching function for call to 'Upp::HttpClient::ExecuteRedirect(Upp::HttpClient::<anon
ymous enum>, Upp::HttpClient::<anonymous enum>, Upp::Callback2<int, int>)'
D:\Program Files\upp\uppsrc/Web/httpcli.h:41: note: candidates are: Upp::String Upp::HttpClient::ExecuteRedirect(int, int, Upp::Gate2<int,
int>)
Re: knowing download speed and ProgressIndicator [message #17181 is a reply to message #17168] Fri, 01 August 2008 11:57 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11991
Registered: November 2005
Ultimate Member
bool Download_Manager_Window::progress_indecator(int x, int all)

returning true will break the process.
Re: knowing download speed and ProgressIndicator [message #17183 is a reply to message #17181] Fri, 01 August 2008 15:25 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

thanks luzr ...... i am sorry as i have a lot of questions

but now the program works but does no thing

i did this

bool Download_Manager_Window::progress_indecator ( int x, int all )
{
	static int timer = 0;
	static int data = 0;
	progress_bar.Set ( x, all );
	timer = clock() - timer;
	data = x - data;
	label_DownloadSpeed.SetText ( DblStr ( ( data / timer ) * 1.0 ) + " KB/S" );

	timer = clock();
	data = x;
	if (x == all)
		return true;
	else
		return false;
}

void Download_Manager_Window::Download_File ( String link )
{
	client.URL ( link );
	String file = client.ExecuteRedirect ( HttpClient::DEFAULT_MAX_REDIRECT, HttpClient::DEFAULT_RETRIES, THISBACK ( progress_indecator ) );

}



and opened it in a thread like this

(new Thread)->Run ( THISBACK1 ( Download_File, "http://cisclub.com/tecno/bta3/vector.rar" ) );


but no thing happen :S :S ...... the window opens and just do nothing

and this is the constructer of the windows which download

Download_Manager_Window::Download_Manager_Window()
{
	CtrlLayout ( *this, "Download" );
	label_DownloadDirectory.SetReadOnly();
	(new Thread)->Run ( THISBACK1 ( Download_File, "http://cisclub.com/tecno/bta3/vector.rar" ) );
}




thanks in advance and i am waiting your response

and sorry for my continuous asking
Re: knowing download speed and ProgressIndicator [message #17187 is a reply to message #17183] Fri, 01 August 2008 17:12 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

please if there is a manual for Web library tell me about it

i want to know what is these arguments for

and i think it's working now but with strange errors ( x == all at first and progress bar some times restart )
Re: knowing download speed and ProgressIndicator [message #17188 is a reply to message #17187] Fri, 01 August 2008 17:28 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

and here is a problem

the program works well and download ....and while downloading it get out of the function .....not only that ......but the function which downloads the file returns nothing

String down_file = client.ExecuteRedirect ( HttpClient::DEFAULT_MAX_REDIRECT, HttpClient::DEFAULT_RETRIES, THISBACK ( progress_indecator ) );


so the file size is zero :S :S

please help me
Re: knowing download speed and ProgressIndicator [message #17192 is a reply to message #17183] Fri, 01 August 2008 21:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11991
Registered: November 2005
Ultimate Member
Why Thread?

Mirek
Re: knowing download speed and ProgressIndicator [message #17196 is a reply to message #17192] Fri, 01 August 2008 23:42 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

thanks for your reply

i use threads so that i can update the GUI ( progress bar / download speed) with out making the program lags

also i want people to can use the program while it's downloading

but i dont know why this errors happen and i dont know why it stop downloading after 2.5 MB as i think and where can i find documentation for these functions
Re: knowing download speed and ProgressIndicator [message #17197 is a reply to message #17196] Sat, 02 August 2008 00:38 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

i tested it on small file (about 150 KB) and it worked very well

but with the first file (about 5MB) it stopped at 2.5 MB as i think

thanks in advance
Re: knowing download speed and ProgressIndicator [message #17218 is a reply to message #17197] Sun, 03 August 2008 10:56 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

Sad Sad Sad

then there is no documentation ......so please help me or tell me a way to know how to know there uses Sad Sad
Re: knowing download speed and ProgressIndicator [message #17226 is a reply to message #17196] Sun, 03 August 2008 14:13 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 11991
Registered: November 2005
Ultimate Member
TeCNoYoTTa wrote on Fri, 01 August 2008 17:42

thanks for your reply

i use threads so that i can update the GUI ( progress bar / download speed) with out making the program lags



That is the reason why there is the Gate callback. You are supposed to update GUI in it.

Also, note that there are severe limitation what you can do in multi-threading (basically, only one main GUI thread is allowed).

Mirek
Previous Topic: making thread
Next Topic: sending post message
Goto Forum:
  


Current Time: Sun Aug 18 19:53:34 CEST 2019

Total time taken to generate the page: 0.01359 seconds