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 

Need help with WiFi/HTTP code

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



Joined: 15 Aug 2005
Posts: 93

PostPosted: Thu Jan 19, 2006 1:03 pm    Post subject: Need help with WiFi/HTTP code Reply with quote

I'm using the following code to download files from an HTTP web server. This is using code Shine posted a while back in IRC.

Code:

int capacity = 1024000;
int len = 0;
u8* buffer = (u8*) malloc(capacity);
while (1) {
   // read data
   int count = sceNetInetRecv(sockListen, (u8*) &buffer[len], capacity - len, 0);

   // in blocking mode it has to return something, otherwise it is closed
   // (which is the default for HTTP/1.0 connections)
   if (count == 0) break;
   
   if (count < 0) {
      pspDebugScreenPrintf("read error: %i\n", err);
      break;
   }

   // adjust buffer, if needed
   len += count;
   if (len + 1024000 > capacity) {
      capacity *= 2;
      buffer = realloc(buffer, capacity);
      if (!buffer) break;
   }
}

// now "len" bytes data are in buffer, add a 0 at end for printing and search for header end
if (buffer) {
   buffer[len] = 0;
   u8* page = strstr((char*) buffer, "\r\n\r\n");
   if (page) {
      page += 4;
      pspDebugScreenPrintf("\n\n%s", page);
      SceUID file;
      file = sceIoOpen("ms0:/PSP/MUSIC/test.mp3", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
      sceIoWrite(file, page, len);
      sceIoClose(file);
   }
   free(buffer);
}


Now this code works GREAT while downloading an MP3 that is under a certain size (from testing, it seems around 6-7mb).
If the MP3 is, say, 8mb, then it will start downloading it and just eventually stop. It slows way down and the WiFi light doesn't blink as much as while it is downloading.

Anyone have any clue why?
Back to top
View user's profile Send private message
planetusa



Joined: 06 Dec 2005
Posts: 21
Location: Asheville

PostPosted: Thu Jan 19, 2006 1:39 pm    Post subject: Reply with quote

I myself had similar issue....I think it's the PSP, and not your code, but I haven't determined for certain.

Right now, I suggest using the ported libcurl

(Bottom of page)

http://forums.ps2dev.org/viewtopic.php?t=4275&start=0
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
planetusa



Joined: 06 Dec 2005
Posts: 21
Location: Asheville

PostPosted: Thu Jan 19, 2006 1:43 pm    Post subject: Reply with quote

As to a why.....I actually notice something, something from when I was working on something else.....the more full buffer gets, the slower the psp is, and is in writing to buffer, if you could write to the file as the data comes in, you may have a solution.

Michael
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Gary13579



Joined: 15 Aug 2005
Posts: 93

PostPosted: Fri Jan 20, 2006 12:50 am    Post subject: Reply with quote

planetusa wrote:
As to a why.....I actually notice something, something from when I was working on something else.....the more full buffer gets, the slower the psp is, and is in writing to buffer, if you could write to the file as the data comes in, you may have a solution.

Michael

In the final code though, I don't want to have to write the file to the memory stick, that is just my way of testing to see if it works.

Now, sorry for showing my noob, but what is libcurl? And how would it solve my problem?

Edit:
curl is a command line tool for transferring files with URL syntax, supporting FTP, FTPS, TFTP, HTTP, HTTPS, TELNET, DICT, FILE and LDAP.

I really need to start googling more, heh.
Again, it seems like this will save it to the memory stick, which I really do not want to do. I want to be able to play the mp3 without having to write it to a file, sort of like WiFi Jukebox, but instead of having to use a custom visual basic program, you can use an HTTP server which will run on any OS.
Back to top
View user's profile Send private message
danzel



Joined: 04 Nov 2005
Posts: 182

PostPosted: Fri Jan 20, 2006 7:50 am    Post subject: Reply with quote

llibcurl has a callback function which you can do what you want with the output.

(Post: http://forums.ps2dev.org/viewtopic.php?p=32816#32816 )
If you have a look at the example I included with the ported libcurl, the function that is being called back is
write_data(void *ptr, size_t size, size_t nmemb, void *stream)

You get sent (size*nmemb) bytes of data pointed to by ptr, and you return the number of bytes from it you have processed.

So you could pass this data straight onto an mp3 decoder or whatever ;)
Back to top
View user's profile Send private message
dbeyer3069



Joined: 19 Dec 2005
Posts: 81

PostPosted: Tue Jan 24, 2006 8:04 am    Post subject: Reply with quote

danzel wrote:
llibcurl has a callback function which you can do what you want with the output.

(Post: http://forums.ps2dev.org/viewtopic.php?p=32816#32816 )
If you have a look at the example I included with the ported libcurl, the function that is being called back is
write_data(void *ptr, size_t size, size_t nmemb, void *stream)

You get sent (size*nmemb) bytes of data pointed to by ptr, and you return the number of bytes from it you have processed.

So you could pass this data straight onto an mp3 decoder or whatever ;)


By the way, the libcurl progress callback works really well too. You need to pass a NULL for the first field (widget object) but it otherwise works great. You can abort a download by returning anything other than 0 in the progress callback. Just some free info for other aspiring libcurl people.

David Beyer
Back to top
View user's profile Send private message
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