forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Http file download, howto

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
aaa801



Joined: 29 Apr 2009
Posts: 2

PostPosted: Sun Nov 22, 2009 9:21 pm    Post subject: Http file download, howto Reply with quote

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
View user's profile Send private message
jojojoris



Joined: 30 Mar 2008
Posts: 261

PostPosted: Sun Nov 22, 2009 11:23 pm    Post subject: Reply with quote

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
View user's profile Send private message
aaa801



Joined: 29 Apr 2009
Posts: 2

PostPosted: Mon Nov 23, 2009 12:09 am    Post subject: Reply with quote

Thanks, now i can start my project =D
Back to top
View user's profile Send private message
m0skit0



Joined: 02 Jun 2009
Posts: 226

PostPosted: Mon Nov 23, 2009 12:48 am    Post subject: Reply with quote

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
View user's profile Send private message
foxss



Joined: 07 Dec 2008
Posts: 6

PostPosted: Sat Nov 28, 2009 7:10 pm    Post subject: zlib error Reply with quote

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
View user's profile Send private message AIM Address MSN Messenger
m0skit0



Joined: 02 Jun 2009
Posts: 226

PostPosted: Sat Nov 28, 2009 7:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
foxss



Joined: 07 Dec 2008
Posts: 6

PostPosted: Mon Nov 30, 2009 1:11 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address MSN Messenger
m0skit0



Joined: 02 Jun 2009
Posts: 226

PostPosted: Mon Nov 30, 2009 1:14 am    Post subject: Reply with quote

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
View user's profile Send private message
Mon Ouïe



Joined: 05 Jul 2009
Posts: 36

PostPosted: Mon Nov 30, 2009 5:12 am    Post subject: Reply with quote

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 :
Code:
-lcurl -lz
Back to top
View user's profile Send private message
foxss



Joined: 07 Dec 2008
Posts: 6

PostPosted: Mon Nov 30, 2009 12:21 pm    Post subject: Reply with quote

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 :
Code:
-lcurl -lz
Back to top
View user's profile Send private message AIM Address MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group