| View previous topic :: View next topic |
| Author |
Message |
aaa801
Joined: 29 Apr 2009 Posts: 2
|
Posted: Sun Nov 22, 2009 9:21 pm Post subject: Http file download, howto |
|
|
| Hea, does anyone have a sample code for connecting to a ap and downloading a file, i have the latest toolchain running on windows (dont ask lol), need urgently for a project |
|
| Back to top |
|
 |
jojojoris
Joined: 30 Mar 2008 Posts: 261
|
Posted: Sun Nov 22, 2009 11:23 pm Post subject: |
|
|
Do you want a easy one with my libcurl+EasyConnect?
http://jojosoft.1free.ws/viewtopic.php?f=7&t=10
| Code: | #include <pspkernel.h>
#include <pspdebug.h>
#include <stdio.h>
#include <curl/curl.h>
#include "easyconnect.h"
PSP_MODULE_INFO("Inet Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
/* 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, 0, 0);
if (thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
FILE * pFile = fopen("tmp.tmp","w");
size_t sizecontent = fwrite(buffer, size, nmemb, pFile);
fclose(pFile);
return sizecontent;
}
int main() {
SetupCallbacks();
EasyConnect connection;
connection.InitGU();
connection.Connect();
connection.TermGU();
pspDebugScreenInit();
pspDebugScreenPrintf("Trying to download:\nhttp://www.google.com\n\n");
if (connection.IsConnected()) {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res == CURLE_OK) {
pspDebugScreenPrintf("File downloaded.\n\n\n");
FILE * pFile = fopen("tmp.tmp","r+");
long int size;
fseek(pFile, 0, SEEK_END);
size = ftell(pFile);
rewind(pFile);
char content[size + 1];
memset(content,0,size+1);
fread(content, size, 1, pFile);
fclose(pFile);
pspDebugScreenPrintf(content);
} else {
pspDebugScreenPrintf("Something went wrong with libcurl: error %i\n", res);
}
} else {
pspDebugScreenPrintf("Something went wrong with libcurl\n");
}
} else {
pspDebugScreenPrintf("You must connect to an access point to use this sample\n");
}
while (1) {
sceKernelDelayThread(10000);
}
sceKernelExitGame();
return 0;
} |
_________________
| Code: | int main(){
SetupCallbacks();
makeNiceGame();
sceKernelExitGame();
} |
|
|
| Back to top |
|
 |
aaa801
Joined: 29 Apr 2009 Posts: 2
|
Posted: Mon Nov 23, 2009 12:09 am Post subject: |
|
|
| Thanks, now i can start my project =D |
|
| Back to top |
|
 |
m0skit0
Joined: 02 Jun 2009 Posts: 226
|
Posted: Mon Nov 23, 2009 12:48 am Post subject: |
|
|
One thing is CSMA/CA (Wifi) connection, and another thing is TCP/IP and plus HTTP. Dont confuse terms. _________________
| The Incredible Bill Gates wrote: | | The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers. |
|
|
| Back to top |
|
 |
foxss
Joined: 07 Dec 2008 Posts: 6
|
Posted: Sat Nov 28, 2009 7:10 pm Post subject: zlib error |
|
|
Looking for help, I got problem when try to do make.
| Code: |
/usr/local/pspdev/lib/gcc/psp/4.3.2/../../../../psp/lib/libcurl.a(content_encodi
ng.o): In function `exit_zlib':
content_encoding.c:(.text+0xa0): undefined reference to `inflateEnd'
/usr/local/pspdev/lib/gcc/psp/4.3.2/../../../../psp/lib/libcurl.a(content_encodi
ng.o): In function `inflate_stream':
content_encoding.c:(.text+0x164): undefined reference to `inflate'
content_encoding.c:(.text+0x23c): undefined reference to `inflateEnd'
/usr/local/pspdev/lib/gcc/psp/4.3.2/../../../../psp/lib/libcurl.a(content_encodi
ng.o): In function `Curl_unencode_deflate_write':
content_encoding.c:(.text+0x3c0): undefined reference to `inflateInit_'
/usr/local/pspdev/lib/gcc/psp/4.3.2/../../../../psp/lib/libcurl.a(content_encodi
ng.o): In function `Curl_unencode_gzip_write':
content_encoding.c:(.text+0x7cc): undefined reference to `zlibVersion'
content_encoding.c:(.text+0x804): undefined reference to `inflateInit2_'
content_encoding.c:(.text+0x858): undefined reference to `inflateInit2_'
collect2: ld returned 1 exit status
make: *** [myproject.elf] Error 1
|
And Makefile
| Code: |
TARGET = myproject
OBJS = main.o easyconnect.o
INCDIR =
CFLAGS = -G0 -Wall -O2
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LIBS= -lstdc++ -lpspgu -lz -lcurl
BUILD_PRX=1
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = My PSP Project
BUILD_PRX = 1
PSP_FW_VERSION = 371
PSP_LARGE_MEMORY = 1
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
|
Thanks! |
|
| Back to top |
|
 |
m0skit0
Joined: 02 Jun 2009 Posts: 226
|
Posted: Sat Nov 28, 2009 7:31 pm Post subject: |
|
|
Seems you dont have zlib installed or you're not linking it correctly. _________________
| The Incredible Bill Gates wrote: | | The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers. |
|
|
| Back to top |
|
 |
foxss
Joined: 07 Dec 2008 Posts: 6
|
Posted: Mon Nov 30, 2009 1:11 am Post subject: |
|
|
Thanks m0skit0 for replying.
My problem still there after I download make and install latest zlib from psp2dev trunk. It give me same error when do make.
| m0skit0 wrote: | | Seems you dont have zlib installed or you're not linking it correctly. |
|
|
| Back to top |
|
 |
m0skit0
Joined: 02 Jun 2009 Posts: 226
|
Posted: Mon Nov 30, 2009 1:14 am Post subject: |
|
|
Have you linked it correctly? I see -lz, r u sure this is correct? _________________
| The Incredible Bill Gates wrote: | | The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers. |
|
|
| Back to top |
|
 |
Mon Ouïe
Joined: 05 Jul 2009 Posts: 36
|
Posted: Mon Nov 30, 2009 5:12 am Post subject: |
|
|
I guess the order is wrong (but -lz is correct): A library which depends on other has to be linked before the libraries it depends on. So, it should be :
|
|
| Back to top |
|
 |
foxss
Joined: 07 Dec 2008 Posts: 6
|
Posted: Mon Nov 30, 2009 12:21 pm Post subject: |
|
|
YES, IT WORKS!
Thanks Mon Ouïe!
| Mon Ouïe wrote: | I guess the order is wrong (but -lz is correct): A library which depends on other has to be linked before the libraries it depends on. So, it should be :
|
|
|
| Back to top |
|
 |
|