Welcome! Log In Create A New Profile

Advanced

Help a noob with online functionality.

Posted by ThatOtherPerson 
Help a noob with online functionality.
January 12, 2009 05:04AM
Hi. I'm sure the answer is probably fairly obvious but I've been going through what I can find about how to do anything internet related with Wii and I still cant figure out how to do what I want to do. I just want to be able to download and read the contents of a text file (TXT, HTML, whatever) from a website. A simple example would be greatly appreciated. I'm seriously stuck and clueless.

On a unrelated note has anyone else been occasionally having trouble with Libwiisprite where it has incorrectly renders sprites that are overlapping each other when one of both of them are significantly zoomed in? Wish I had a screenshot to show but if its happened to you then I'm sure you know what i mean. Is there any way to fix it or is it just an unavoidable flaw/limitation of Libwiisprite? Its not really important and not worth starting another thread to ask but if anybody knows it would be cool to find out.



Edited 1 time(s). Last edit at 01/12/2009 06:31AM by ThatOtherPerson.
Re: Help a noob with online functionality.
January 12, 2009 05:10AM
I'm actually in the process of writing something like that, but if you don't want to wait for me to finish you should look at the ftpii code or teknecal's netsend example on the Homebrew Browser wiki page.

Also, this tutorial seems pretty good for learning the sockets interface in general. [beej.us]

The stuff about IPv6 isn't relevant to Wii, and in some places he mentions functions that are obsolete but they are the ones that are on the wii. Check network.h in your libogc folder to see what functions you have.

OK, here's my shoddy example thing:
[pastebin.com]

I cobbled it together from tutorials and such, so if anyone could critique it that would be great. It probably does a lot of things unnecessarily or wrong since I used different parts of different tutorials, but it will download the index of google, or any other site.

I used the beej.us tutorial, this tutorial on HTTP (also see RFC 1945 for reference), this other general network tutorial, and teknecal's netsend example.

Note that this only prints out the contents of the file, but doesn't save it anywhere. That's my goal for tomorrow, as well as some cleanup/reducing random bits of code that might not be necessary.



Edited 3 time(s). Last edit at 01/12/2009 10:52AM by iofthestorm.
Re: Help a noob with online functionality.
January 12, 2009 05:36PM
Thank you so much for your reply! Your shoddy example is probably the simplest most helpful thing I've seen on the subject :) I just read through it and I'm really hyped to compile/test/edit it later when I have more time and I'm looking forward to seeing you update it.
Re: Help a noob with online functionality.
January 12, 2009 07:23PM
Sure, no problem. You should really check out all the links I included in my posts though, if you want to do something besides download the index of google and display it flying past on your screen in bare HTML glory you will need to understand everything. I tried to comment it as well as I could but I'll break it down some more later. By the way, if you try to run it you might want to choose a simple page with just a line of text or something, because even Google's simple homepage is not so simple anymore and quickly flies past on your screen, so you can't see the HTTP headers which are probably useful to see. But you can see examples of those on some of the tutorials and informative links I listed. Anyway, good luck with your projects, I'll probably update with some more stuff in a few hours.

Edit: OK, here's a nicer version.

[pastebin.com]

It lets you specify the file URL you want to download and fetches it appropriately. The default is example.com/index.html, which is much smaller than Google's home page and lets you see more info about the headers and stuff. Although you can get that info from the RFCs as well, I like looking at real examples. I put the downloading bit in its own function so that you can copy it out easily if you want. I'll try to tackle writing to SD in maybe half an hour or so, after I grab some lunch.

There's a struct at the top that I'm going to be using for when I start parsing the http response, but currently it does nothing. On second thought, I should tackle that before I do writing to a file.

I intend to write a tutorial eventually once I finish all this, because there's a distinct dearth of tutorials on Wii network coding, or well Wii coding in general.



Edited 3 time(s). Last edit at 01/12/2009 10:34PM by iofthestorm.
Re: Help a noob with online functionality.
January 13, 2009 07:08AM
Please do at the very least add proxy support, there will always be people that has to use a proxy for one reason or another.
Also, do remember that http requests can have quite a lot of headers. You should ideally design the library to make it easy to access any header, no matter the name.
Re: Help a noob with online functionality.
January 13, 2009 10:33AM
Woah, I'm not writing a library (wouldn't know how - this is my first nontrivial C program) but I'll be sure to try and make it as general as possible. The HTTP header stuff goes in a struct so I think that should make it easy to access the header once I start storing all the header fields. Anyway, here's a nicer version of the above that downloads the file to temp.txt on the root of your SD, and doesn't print out headers, and checks to see if the amount downloaded matches the content length header field.

[pastebin.com]

Tomorrow I will throw this into an SVN repo though, and begin actually developing my rss reader app.



Edited 1 time(s). Last edit at 01/13/2009 10:36AM by iofthestorm.
Re: Help a noob with online functionality.
January 13, 2009 07:01PM
I'm not sure what I'm doing wrong but it never seems to work. I keep getting the "Failed to initialize network" response and it shuts down. I haven't tried any address other then example.com/index.html yet but I assume the result would still be the same with another. Also I get the following warnings when compiling.

> "make" 
source.cpp
c:/devkitPro/projects/wiinode/source/source.cpp: In function 'int displayInetFile(char*)':
c:/devkitPro/projects/wiinode/source/source.cpp:104: warning: comparison between signed and unsigned integer expressions
c:/devkitPro/projects/wiinode/source/source.cpp: In function 'int main(int, char**)':
c:/devkitPro/projects/wiinode/source/source.cpp:124: warning: deprecated conversion from string constant to 'char*'
linking ... boot.elf
output ... boot.dol

> Process Exit Code: 0
> Time Taken: 00:04

The previous two versions you posted got errors and wouldn't compile at all.
Re: Help a noob with online functionality.
January 13, 2009 07:50PM
I'm using C, not C++. That might make a difference, since C++ is more strict than C. Oh, and you need to add libfat to your makefile, if you didn't already, but I assume you did or else you would have a compile error about fatInitDefault(). Also, are you running the latest devkitPPC? It compiles fine on my machine with the latest devkitPPC as of a few days ago, dunno if something was added recently or not.

To continue your other random thread, I've never used libwiisprite and I haven't really written any nontrivial C++ code. Do I have to use C++ to use libwiisprite? I was hoping I would be able to switch to C++ without changing anything but it looks like I can't.

If your network is failing to initialize, I don't know whether your network might be the problem. But I guess if you're sending it via wiiload it probably isn't.

Aaand, here's my Google Code site complete with SVN repos. [code.google.com]



Edited 2 time(s). Last edit at 01/13/2009 10:52PM by iofthestorm.
Re: Help a noob with online functionality.
January 14, 2009 12:52AM
I switched over to C and it compiled fine without anymore warnings :) I still get "Failed to initialize network" when I run it though. I was actually moving it back and forth from my PC to Wii on SD card but I don't think there is anything wrong with my network (All my online Wii games like Mario Kart and Call of Duty: World at War work fine when I'm playing online) and I just tried sending it over with wiiload which worked fine (though it still had the same failure when it ran).

To be honest I dont even really know what exactly the differances are between c and C++ and I wasn't even sure which I was using initially. I've made some half complete games that work as they should but like I said in the title I'm still fairly noobish. So I don't really know whether or not Libwiisprite would work with C but the wiibrew wiki about it makes a point of stating that its a C++ sprite library so I think it probable is made specifically to be used with C++.
Re: Help a noob with online functionality.
January 14, 2009 12:56AM
Oh, okay. I really don't know what the problem is then because I just used the if_config() function which initializes the network automatically for you. It gives up after a set number of times, so maybe you just need to keep trying. You could try throwing that part in a while loop so that it keeps trying until you press a button or something, maybe it just takes more tries on your network.

As for the libwiisprite stuff, I suppose I'll figure it out. I guess C is mostly compatible with C++ but I don't know the subtleties yet (or really, I don't know anything C++ specific besides cout and the different headers).
Re: Help a noob with online functionality.
January 14, 2009 01:15AM
Never mind. It was my copy of devkitPro. turns out my version was out of date (not sure when I updated it last) so I got the update, recompiled, and its working now :D
Re: Help a noob with online functionality.
January 14, 2009 07:19AM
You really should fix the warnings instead of just dodging them. They indicate real issues that you should fix.
The first one is quite easy, use the right pointer datatype, it's not const correct.
The later one means what it says, you are comparing signed with unsigned, this is an error because on how very big numbers are represented differently in each type, fix it by making both operands either both be signed or none be signed.
Re: Help a noob with online functionality.
January 14, 2009 07:30AM
Oh ok, didn't understand what it meant by const. I'm still working out pointers. And for the other one, I didn't realize that one was signed and one wasn't. I'll just make them both signed since they are filesizes, although that does mean I'll have to subtract off the header length at the end.

Oh huh, didn't realize that C distinguishes between a string constant and a char *. I should probably just change the URL i load into a variable char *, as this is going to evolve into something more modular anyway. From now on, all changes will be on the google code SVN repo I linked to above. Pastebin is pretty nice when you're just banging away at the keyboard but having real revision control is much nicer.

Wait, could you clarify what I would have to do to make a string constant into a char *? I'm really confused, because this function will need to take in a char * and not a const char * eventually since it will be loading a URL from the user's input, but for now I'm just testing it with a default url.



Edited 2 time(s). Last edit at 01/14/2009 07:45AM by iofthestorm.
Re: Help a noob with online functionality.
January 15, 2009 05:10PM
const means that the function will not change the data, it does not mean that the data can not vary due to other code.
Re: Help a noob with online functionality.
January 16, 2009 03:31AM
Oh really? I assumed it would be restricted to only string constants. Thanks, I will change that right away then.
Sorry, only registered users may post in this forum.

Click here to login