Advice on loading text from internet

5 posts / 0 new
Last post
KyleHatch
KyleHatch's picture
Offline
Mobile Conjurer
Joined: 17 Dec 2011
Posts:
Advice on loading text from internet

Hi. i'm looking to make a relatively simple app that reads text data from the internet into a certain screen. This can be a simple text file or xml, or whatever.

The idea is that the app doesn't need updating everytime the information does, allowing a simple update of the txt file (or whatever) upload to the server and when the app runs it checks the file and loads in the text.

I've looked at a few different options, http://www.mosync.com/documentation/tutorials/downloading-data-internet-0#Using_the_Downloader_Classes_in_C < looks promising but not entirely sure.

I've also look at the connection example and how that works.

If someone could point me in the right direction, i would appreciate it. Alot of the examples seem to be overkill for what i want to do, but that might just be the way it is.

Kyle.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Sam Pickard
rival's picture
Online
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Yeah, getting data can be a bit labourious, but I often find that I reuse those components again and again. The link you've got is the best one to use. If you have the AppMancer library (www.appmancer.com), then there is an AMDownload library.

This takes a lot of the legwork out of the download, but uses slightly more memory.

DownloadRequest* req = DownloadManager::createRequest(this);
req->setUrl("http://www.myserver.com/mydata");
DownloadManager::enqueue(req);
Sam Pickard
rival's picture
Online
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Sorry, I forgot to say not to discount the Downloader class. The example in the tutorial you looked at has a lot of additional UI code. The Downloader class can actually be used in just a few lines of code. You need to create the downloader, and implement the finishedDownloading() method.

KyleHatch
KyleHatch's picture
Offline
Mobile Conjurer
Joined: 17 Dec 2011
Posts:

I'm now back onto this part of the program after getting the other things fixed. So i've tried to write my own extending class using the AMDownload.

Download.cpp wrote:

#include "Download.h"

void Download::downloadData(const char* URL)
{
req = DownloadManager::createRequest(this);
req->setUrl(URL);
DownloadManager::enqueue(req);
downloadFinished(req);
}

void Download::downloadFinished(DownloadRequest* request)
{
MAHandle data = request->getData();
mData = data;
}

MAHandle Download::ReturnData()
{
return mData;
}

and..

Download.h wrote:

#ifndef DOWNLOAD_H_
#define DOWNLOAD_H_

#include
#include "../std.h"

using namespace AMDownload;

class Download : public DownloadRequestListener
{
public:
Download() {}
~Download() {}

void downloadData(const char* URL);
void downloadFinished(DownloadRequest* request);
MAHandle ReturnData();
private:
DownloadRequest* req;
MAHandle mData;

Download(const Download& x) {}
};

#endif /* DOWNLOAD_H_ */

Seems good so far (maybe), i then go into the class i want to load the xml in, and where before i did...

xmldoc = XmlToData::toXml(LANGUAGE_NETHER);

i now do...

mDownload = new Download();
mDownload->downloadData("http://www.king-of-the-geeks.com/nether.xml"); << working link
xmldoc = XmlToData::toXml(mDownload->ReturnData());

then so on....as before when it was just a resource file.

BUT....

MoSync Panic 40001. "Invalid resource type" The panic occurred in the syscall maGetDataSize.

it seems to be in XmlToData, line 8 which is...int len = maGetDataSize(data);...sure one xml file as a resource and one downloaded can't be that different. so i assume the download has gone wrong somewhere. Any ideas would be useful.

Thanks Kyle.

KyleHatch
KyleHatch's picture
Offline
Mobile Conjurer
Joined: 17 Dec 2011
Posts:

anyone, any ideas on this? It's pretty much the only component of my app left to go in....