| View previous topic :: View next topic |
| Author |
Message |
FaderX
Joined: 01 Mar 2008 Posts: 28
|
Posted: Sat Mar 01, 2008 12:45 pm Post subject: downloading files?? from internet.....How? |
|
|
Hey all im new here, lol
SO i have a homebrew which accesses the internet,.....How do you download a file do you use?
| Code: | | copy_file("http://website.com/file.extension, "ms0:/file.extension"); |
I've tried that & it currently doesn't work?? & im connected to the internet.
im fairly sure its not going to work, but i could be wrong.
i know Dark_AleX /moonlight does it in the 3.90 M33 Unpacker/Downloader thingy
If someone knows what it is please let me know, or if there's a place that shows it already can you point me in that direction please,
Thanks all,
FaderX
p.s. I've checked usin the search option as usual in forums, & Google, and I've ended up with no results in what I'm looking for. |
|
| Back to top |
|
 |
weltall
Joined: 20 Feb 2004 Posts: 310
|
Posted: Sat Mar 01, 2008 4:11 pm Post subject: |
|
|
| except access point connection and adress resolving which is available from samples in the sdk everything else it's the same as with the pc, so search for a good network connection in c/c++ tutorial with google |
|
| Back to top |
|
 |
moonlight
Joined: 26 Oct 2005 Posts: 567
|
Posted: Sat Mar 01, 2008 7:00 pm Post subject: |
|
|
As welltall said, you could use whatever network code and create a very basic http client, as for downloading a file you don't need much complicated things.
Anyways, the M33 updater uses the firmware libhttp which has not been added yet to the sdk, and uses it like it has been seen in the sony xmb network update.
Basically, after loading the other network modules, load http ones:
| Code: |
if (sceUtilityLoadNetModule(PSP_NET_MODULE_PARSEURI) < 0)
// error here
if (sceUtilityLoadNetModule(PSP_NET_MODULE_PARSEHTTP) < 0)
// error here
if (sceUtilityLoadNetModule(PSP_NET_MODULE_HTTP) < 0)
// error here
|
(for unload, unload them in reverse order).
And usage of library:
| Code: |
char *the_url = "http://www.someweb.com/file.bin";
u8 buf[100*1024] __attribute__((aligned(64))); // this should go as global var
u32 filesize;
int nbytes;
if (sceHttpInit(20000) < 0)
// error here
int template = sceHttpCreateTemplate("MyUserAgent/0.0.1 libhttp/1.0.0", 1, 1);
if (template < 0)
// error here
if (sceHttpSetResolveTimeOut(template, 3000000) < 0)
// error here
if (sceHttpSetRecvTimeOut(template, 60000000) < 0)
// error here
if (sceHttpSetSendTimeOut(template, 60000000) < 0)
// error here
int connection = sceHttpCreateConnectionWithURL(template, the_url, 0);
if (connection < 0)
// error here
int request = sceHttpCreateRequestWithURL(connection, 0, the_url, 0);
if (request < 0)
// error here
if (sceHttpSendRequest(request, 0, 0) < 0)
// error here
int status = sceHttpGetStatusCode(request, &status);
if (status != 200)
// error here
if (sceHttpGetContentLength(request, &filesize) < 0)
// error here
printf("File size = %d\n" filesize);
while ((nbytes = sceHttpReadData(request, buf, sizeof(buf))) != 0)
{
if (nbytes < 0)
// error here, abort loop
// Write nbytes to a file or whatever
}
|
Of course, you have to create the stub or the library for libhttp
sceHttp.S:
| Code: |
.set noreorder
#include "pspstub.s"
STUB_START "sceHttp",0x00090011,0x00530005
STUB_FUNC 0x0282A3BD,sceHttpGetContentLength
STUB_FUNC 0x1F0FC3E3,sceHttpSetRecvTimeOut
STUB_FUNC 0x47940436,sceHttpSetResolveTimeOut
STUB_FUNC 0x4CC7D78F,sceHttpGetStatusCode
STUB_FUNC 0x9988172D,sceHttpSetSendTimeOut
STUB_FUNC 0x9B1F1F36,sceHttpCreateTemplate
STUB_FUNC 0xAB1ABE07,sceHttpInit
STUB_FUNC 0xB509B09E,sceHttpCreateRequestWithURL
STUB_FUNC 0xBB70706F,sceHttpSendRequest
STUB_FUNC 0xCDF8ECB9,sceHttpCreateConnectionWithURL
STUB_END
|
|
|
| Back to top |
|
 |
FaderX
Joined: 01 Mar 2008 Posts: 28
|
Posted: Sat Mar 01, 2008 10:11 pm Post subject: |
|
|
thanks weltall & moonlight, i'll have a look in the morning, its about 10:00 & im tired coz i just got back from a engagement party.
i appreciate it the help,
FaderX |
|
| Back to top |
|
 |
Insert_witty_name
Joined: 10 May 2006 Posts: 376
|
Posted: Sun Mar 02, 2008 9:14 am Post subject: |
|
|
I'll be adding libhttp to the SDK soon, I'm working on it currently.
It's just a wrapper for the socket functions anyway, |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sun Mar 02, 2008 9:54 am Post subject: |
|
|
| There's also curl in the repo. Getting files across the net with curl is pretty simple. |
|
| Back to top |
|
 |
FaderX
Joined: 01 Mar 2008 Posts: 28
|
Posted: Sun Mar 02, 2008 11:53 am Post subject: |
|
|
This is my main.c
| Code: |
//Headers are here
PSP_MODULE_INFO("DL_File", 0x0800, 1, 0);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_VSH);
#define printf pspDebugScreenPrintf
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread,
0x11, 0xFA0, PSP_THREAD_ATTR_USER, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int connect_to_apctl(int config)
{
int sceWlanGetSwitchState(void);
int err;
int stateLast = -1;
if (sceWlanGetSwitchState() != 1)
pspDebugScreenClear();
while (sceWlanGetSwitchState() != 1)
{
pspDebugScreenSetXY(0, 0);
printf("enable WLAN to continue.\n");
sceKernelDelayThread(1000 * 1000);
}
err = sceNetApctlConnect(config);
if (err != 0)
{
printf("sceNetApctlConnect returns %08X\n", err);
return 0;
}
printf("Connecting...\n");
while (1)
{
int state;
err = sceNetApctlGetState(&state);
if (err != 0)
{
printf("sceNetApctlGetState returns $%x\n", err);
break;
}
if (state != stateLast)
{
printf(" Connection state %d of 4.\n", state);
stateLast = state;
}
if (state == 4)
{
break;
}
sceKernelDelayThread(50 * 1000);
}
printf("connected!\n");
sceKernelDelayThread(3000 * 1000);
if (err != 0)
{
return 0;
}
return 1;
}
char *getconfname(int confnum)
{
static char confname[128];
sceUtilityGetNetParam(confnum, PSP_NETPARAM_NAME, (netData *)confname);
return confname;
}
int net_thread(SceSize args, void *argp)
{
int selComponent = 1;
printf("Connection %d (%s) to connect...\n", selComponent, getconfname(selComponent));
if (connect_to_apctl(selComponent))
{
char szMyIPAddr[32];
if (sceNetApctlGetInfo(8, szMyIPAddr) != 0)
{
strcpy(szMyIPAddr, "unknown IP address");
printf("ip: %s\n", szMyIPAddr);
sceKernelSleepThread();
}
}
return 0;
}
int InitialiseNetwork(void)
{
int err;
//Load the Network modules
printf("load network modules... ");
err = sceUtilityLoadNetModule(PSP_NET_MODULE_COMMON);
if (err != 0)
{
printf("Error, could not load PSP_NET_MODULE_COMMON %08X\n", err);
return 1;
}
err = sceUtilityLoadNetModule(PSP_NET_MODULE_INET);
if (err != 0)
{
printf("Error, could not load PSP_NET_MODULE_INET %08X\n", err);
return 1;
}
printf("Done\n");
err = pspSdkInetInit();
if (err != 0)
{
printf("Error, could not initialize the network %08X\n", err);
return 1;
}
//Now the http modules
if (sceUtilityLoadNetModule(PSP_NET_MODULE_PARSEURI) < 0)
{
// error here
printf("Error, Could Not initialize the Net module PARSEURI\n");
return 1;
}
if (sceUtilityLoadNetModule(PSP_NET_MODULE_PARSEHTTP) < 0)
{
// error here
printf("Error, Could Not initialize the Net module PARSEHTTP\n");
return 1;
}
if (sceUtilityLoadNetModule(PSP_NET_MODULE_HTTP) < 0)
{
// error here
printf("Error, Could Not initialize the Net module HTTP\n");
return 1;
}
return 0;
}
/* Simple thread */
int main(int argc, char **argv)
{
SceUID thid;
SetupCallbacks();
pspDebugScreenInit();
pspDebugScreenClear();
if (InitialiseNetwork() != 0)
{
printf("Error! Network Couldn't be Initialised\n");
sceKernelSleepThread();
}
thid = sceKernelCreateThread("net_thread", net_thread, 0x18, 0x10000, PSP_THREAD_ATTR_USER, NULL);
if (thid < 0)
{
printf("thread couldnt be created!\n");
sceKernelSleepThread();
}
sceKernelStartThread(thid, 0, NULL);
pspDebugScreenSetTextColor(0xFFFFF1);
printf("Some text crap\n");
while (1)
{
SceCtrlData pad;
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons & PSP_CTRL_CROSS)
{
break;
}
else if (pad.Buttons & PSP_CTRL_RTRIGGER)
{
sceKernelExitGame();
}
sceKernelDelayThread(10000);
}
char *the_url = "http://someweb.com/file.bin";
u8 buf[100*1024] __attribute__((aligned(64))); // this should go as global var
u32 filesize;
int nbytes;
if (sceHttpInit(20000) < 0)
{
// error here
printf("Error\n");
}
int template = sceHttpCreateTemplate("MyUserAgent/0.0.1 libhttp/1.0.0", 1, 1);
if (template < 0)
{
// error here
printf("Error\n");
}
if (sceHttpSetResolveTimeOut(template, 3000000) < 0)
{
// error here
printf("Error\n");
}
if (sceHttpSetRecvTimeOut(template, 60000000) < 0)
{
// error here
printf("Error\n");
}
if (sceHttpSetSendTimeOut(template, 60000000) < 0)
{
// error here
printf("Error\n");
}
int connection = sceHttpCreateConnectionWithURL(template, the_url, 0);
if (connection < 0)
{
// error here
printf("Error\n");
}
int request = sceHttpCreateRequestWithURL(connection, 0, the_url, 0);
if (request < 0)
{
// error here
printf("Error\n");
}
if (sceHttpSendRequest(request, 0, 0) < 0)
{
// error here
printf("Error\n");
}
int status = sceHttpGetStatusCode(request, &status);
if (status != 200)
{
// error here
printf("Error\n");
}
if (sceHttpGetContentLength(request, &filesize) < 0)
{
// error here
printf("Error\n");
}
printf("File size = %d\n", filesize);
while ((nbytes = sceHttpReadData(request, buf, sizeof(buf))) != 0)
{
if (nbytes < 0)
{
// error here, abort loop
printf("Error\n");
}
// Write nbytes to a file or whatever
}
return 0;
}
|
Now my makefile, i sorta adapt this makefile to everything so it may be wrong as usual, im using the kernels 3.XX or 1.50 either one. atm im using the 3.XX
| Code: | TARGET = DL_File
OBJS = main.o HttpRequest.o HttpPacket.o HttpResponse.o
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LIBS = sceHttp.S -lpsppower -lpspgu -lz -lm -lpspwlan sceWlanDrv_lib.S sceWlanDrv.S
LDFLAGS =
PSP_FW_VERSION = 340
BUILD_PRX = 1
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = DL_File
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
|
I know im going wrong, just can't correct it, It compiles for me, but doesnt load now? it gets past the gameboot then....Black Screen. Idea's anyone.
i also tried in user,
| Code: | PSP_MODULE_INFO("DL_File", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER); |
Do i need to add more stuff??, take stuff out, lol. |
|
| Back to top |
|
 |
gambiting
Joined: 17 Aug 2006 Posts: 154
|
Posted: Tue Mar 04, 2008 3:26 am Post subject: |
|
|
You have to define Heap size:
| Code: | | PSP_HEAP_SIZE_MAX(); |
put it after psp module info.Should help. |
|
| Back to top |
|
 |
FaderX
Joined: 01 Mar 2008 Posts: 28
|
Posted: Tue Mar 04, 2008 3:46 pm Post subject: |
|
|
| gambiting wrote: | You have to define Heap size:
| Code: | | PSP_HEAP_SIZE_MAX(); |
put it after psp module info.Should help. |
thanks, but it still doesnt work, any more idea's?? |
|
| Back to top |
|
 |
moonlight
Joined: 26 Oct 2005 Posts: 567
|
Posted: Tue Mar 04, 2008 4:42 pm Post subject: |
|
|
| Well, as i put in the comments, the 100 KB global var would go better as global variable. |
|
| Back to top |
|
 |
FaderX
Joined: 01 Mar 2008 Posts: 28
|
Posted: Sat Mar 15, 2008 1:59 pm Post subject: |
|
|
| i also tried using a prx that loads, it fails aswell, i used the Cfe 2.2 ftpd.prx btw. any other idea's to get this working?? |
|
| Back to top |
|
 |
Insert_witty_name
Joined: 10 May 2006 Posts: 376
|
Posted: Mon Mar 24, 2008 11:16 am Post subject: |
|
|
| I've commited libhttp to the SDK, revision 2376. |
|
| Back to top |
|
 |
FaderX
Joined: 01 Mar 2008 Posts: 28
|
Posted: Mon Mar 24, 2008 4:45 pm Post subject: |
|
|
| Insert_witty_name wrote: | | I've commited libhttp to the SDK, revision 2376. |
Thanks man!! |
|
| Back to top |
|
 |
PiCkDaT
Joined: 04 Oct 2007 Posts: 69
|
Posted: Mon Mar 24, 2008 10:20 pm Post subject: |
|
|
can you use a TCP/IP Socket to get files from the internet instead of a UDP(since it loses data). Just wondering because I have seen examples on how to get HTML data from a webserver but it was through UDP... _________________ Enlighten me, Reveal my fate -- Follow - Breaking Benjamin |
|
| Back to top |
|
 |
ne0h
Joined: 21 Feb 2008 Posts: 386
|
Posted: Mon Mar 24, 2008 10:49 pm Post subject: |
|
|
| Where I can find the lastest build of PSP SDK? In the home there is a old build of PSP SDK! |
|
| Back to top |
|
 |
PiCkDaT
Joined: 04 Oct 2007 Posts: 69
|
Posted: Tue Mar 25, 2008 3:00 am Post subject: |
|
|
in cygwin type
svn co svn://svn.ps2dev.org/psp/trunk/pspsdk/
cd pspsdk
make
make install _________________ Enlighten me, Reveal my fate -- Follow - Breaking Benjamin |
|
| Back to top |
|
 |
ne0h
Joined: 21 Feb 2008 Posts: 386
|
Posted: Tue Mar 25, 2008 3:36 am Post subject: |
|
|
| I'm not use the Cygwin, i use the Heimdall win32 like toolchain!! |
|
| Back to top |
|
 |
PiCkDaT
Joined: 04 Oct 2007 Posts: 69
|
Posted: Tue Mar 25, 2008 3:48 am Post subject: |
|
|
hmm... well you should try to go with Cygwin if you want easy updates.. Cygwin lets you install libs and update the SDK easily.. downside to installing Cygwin and toolchain is it takes forever.. but after that it works fine. _________________ Enlighten me, Reveal my fate -- Follow - Breaking Benjamin |
|
| Back to top |
|
 |
Gh0st-UPMS
Joined: 17 Feb 2008 Posts: 23
|
Posted: Sat Mar 29, 2008 1:12 am Post subject: |
|
|
If you get errors saying no make file then add ./bootstrap then type the above commands.
It's in the Read Me that comes with the sdk. |
|
| Back to top |
|
 |
homemister
Joined: 24 Mar 2008 Posts: 25
|
Posted: Sat Mar 29, 2008 10:52 am Post subject: |
|
|
does anyony know how to use the Socket Functions eg socket:recv() socket:send(). to download files from the web?.
Regards
Homemister |
|
| Back to top |
|
 |
pegasus2000
Joined: 12 Jul 2006 Posts: 160
|
Posted: Sat Mar 29, 2008 7:45 pm Post subject: |
|
|
| homemister wrote: | does anyony know how to use the Socket Functions eg socket:recv() socket:send(). to download files from the web?.
Regards
Homemister |
Install Nanodesktop. In 3 rows of code you can download what you
want.... |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sun Mar 30, 2008 4:39 am Post subject: |
|
|
| homemister wrote: | | does anyony know how to use the Socket Functions eg socket:recv() socket:send(). to download files from the web? |
You use them the same way you would if you weren't on a PSP.
Seriously, folks, some of y'all need some refresher courses on programming, and we don't do that here. |
|
| Back to top |
|
 |
wagon
Joined: 18 Mar 2008 Posts: 8
|
Posted: Thu Apr 03, 2008 6:21 pm Post subject: headfiles |
|
|
src/GameApp.cpp: In function 'int net_thread(SceSize, void*)':
src/GameApp.cpp:197: error: 'sceHttpInit' was not declared in this scope
src/GameApp.cpp:204: error: expected unqualified-id before 'template'
src/GameApp.cpp:206: error: expected primary-expression before 'template'
src/GameApp.cpp:206: error: expected `)' before 'template'
src/GameApp.cpp:211: error: expected primary-expression before 'template'
src/GameApp.cpp:211: error: 'sceHttpSetResolveTimeOut' was not declared in this scope
src/GameApp.cpp:216: error: expected primary-expression before 'template'
src/GameApp.cpp:216: error: 'sceHttpSetRecvTimeOut' was not declared in this scope
src/GameApp.cpp:221: error: expected primary-expression before 'template'
src/GameApp.cpp:221: error: 'sceHttpSetSendTimeOut' was not declared in this scope
src/GameApp.cpp:226: error: expected primary-expression before 'template'
src/GameApp.cpp:226: error: 'sceHttpCreateConnectionWithURL' was not declared in this s
src/GameApp.cpp:232: error: 'sceHttpCreateRequestWithURL' was not declared in this scop
src/GameApp.cpp:238: error: 'sceHttpSendRequest' was not declared in this scope
src/GameApp.cpp:243: error: 'sceHttpGetStatusCode' was not declared in this scope
src/GameApp.cpp:250: error: 'sceHttpGetContentLength' was not declared in this scope
src/GameApp.cpp:256: warning: format '%d' expects type 'int', but argument 2 has type '
src/GameApp.cpp:258: error: 'sceHttpReadData' was not declared in this scope
code without headfiles
the head files? where? any one tell me? |
|
| Back to top |
|
 |
Insert_witty_name
Joined: 10 May 2006 Posts: 376
|
Posted: Thu Apr 03, 2008 7:03 pm Post subject: |
|
|
| Insert_witty_name wrote: | | I've commited libhttp to the SDK, revision 2376. |
Use header and library from the SDK. psphttp.h and -lpsphttp |
|
| Back to top |
|
 |
wagon
Joined: 18 Mar 2008 Posts: 8
|
Posted: Fri Apr 04, 2008 4:25 pm Post subject: |
|
|
| Insert_witty_name wrote: | | Insert_witty_name wrote: | | I've commited libhttp to the SDK, revision 2376. |
Use header and library from the SDK. psphttp.h and -lpsphttp |
i'm bad in english. i still don't know what you mean.
there is no psphttp.h in my pspsdk include dir.
may be it's not the latest one.
where can i find your psphttp.h and the lib.
thank you very much. |
|
| Back to top |
|
 |
DeathCradle
Joined: 19 Jan 2008 Posts: 6
|
Posted: Fri Apr 04, 2008 5:09 pm Post subject: |
|
|
Read PiCkDaT's post in this thread, he told ne0h how to.
|
|
| Back to top |
|
 |
Vincent_M
Joined: 03 Apr 2007 Posts: 73
|
Posted: Sat Apr 05, 2008 12:57 am Post subject: |
|
|
| @FaderX: What exactly was going on when you started up your application? Did anything go wrong, or did nothing work? |
|
| Back to top |
|
 |
FaderX
Joined: 01 Mar 2008 Posts: 28
|
Posted: Sat Apr 05, 2008 8:04 am Post subject: |
|
|
| Vincent_M wrote: | | @FaderX: What exactly was going on when you started up your application? Did anything go wrong, or did nothing work? |
it loaded until i added libhttp functions. i also tried a prx which worked until it reached the http functions, moonlight has to be right about the global variable. im guna try it again when i get a working app. |
|
| Back to top |
|
 |
|