Post: File Downloader Code (For SPRX)
07-24-2017, 10:30 PM #1
Tustin
Balls of Steel
(adsbygoogle = window.adsbygoogle || []).push({}); I wrote this code with the intention of making a auto updater for Lexicon a while back but ran into problems with file permissions so it was never used. Figured someone here could find it useful for something. You need to add this code to your sprx project, and then create a listening server in whatever language you want to serve the file.


C++ code: (I can't remember if the progress bar thing worked properly or not)



Server code (written in PHP =Z):



This is a basic example that will help you get started. Although if you want to modify this any further you probably want to do some research on socket programming before messing with this.
Last edited by Tustin ; 07-24-2017 at 10:34 PM.

The following 2 users say thank you to Tustin for this useful post:

PhucedMODZ, Smoulougde
07-30-2017, 02:25 PM #2
Smoulougde
S.P.E.C.I.A.L
Originally posted by Tustin View Post
I wrote this code with the intention of making a auto updater for Lexicon a while back but ran into problems with file permissions so it was never used. Figured someone here could find it useful for something. You need to add this code to your sprx project, and then create a listening server in whatever language you want to serve the file.


C++ code: (I can't remember if the progress bar thing worked properly or not)



Server code (written in PHP =Z):



This is a basic example that will help you get started. Although if you want to modify this any further you probably want to do some research on socket programming before messing with this.


Hi, i have one error for RESPONSE_BUFFER_SIZE. Visual said "RESPONSE_BUFFER_SIZE is not defined"
What is RESPONSE_BUFFER_SIZE ?
07-30-2017, 05:35 PM #3
Tustin
Balls of Steel
Originally posted by Smoulougde View Post
Hi, i have one error for RESPONSE_BUFFER_SIZE. Visual said "RESPONSE_BUFFER_SIZE is not defined"
What is RESPONSE_BUFFER_SIZE ?

It's just the size of the web request buffer. You can set it to whatever you want just make sure the response size (headers + body) is less than the buffer. I would just use 2048 for the size.
07-30-2017, 08:52 PM #4
Smoulougde
S.P.E.C.I.A.L
Originally posted by Tustin View Post
It's just the size of the web request buffer. You can set it to whatever you want just make sure the response size (headers + body) is less than the buffer. I would just use 2048 for the size.


Ok i see, thanks for the reply. I will try the function in php soon for files of my menu (ini / txt and sprx) Smile
07-30-2017, 09:43 PM #5
Originally posted by Tustin View Post
I wrote this code with the intention of making a auto updater for Lexicon a while back but ran into problems with file permissions so it was never used. Figured someone here could find it useful for something. You need to add this code to your sprx project, and then create a listening server in whatever language you want to serve the file.


C++ code: (I can't remember if the progress bar thing worked properly or not)



Server code (written in PHP =Z):



This is a basic example that will help you get started. Although if you want to modify this any further you probably want to do some research on socket programming before messing with this.


Code looks a little funky. Why are you "receiving" the whole size of the buffer if you plan to iterate through it? Shouldn't you download size/100 bytes (per say) at a time or something?
And with your server code, do you have to set it up like that? Could you not just point the program to the direct link for the file?
07-31-2017, 12:35 AM #6
Tustin
Balls of Steel
Originally posted by John View Post
Code looks a little funky. Why are you "receiving" the whole size of the buffer if you plan to iterate through it? Shouldn't you download size/100 bytes (per say) at a time or something?
And with your server code, do you have to set it up like that? Could you not just point the program to the direct link for the file?


The server socket will serve all of the bytes of the file but the client socket isn't necessarily reading it all in at once. It's not reading in the whole file (well it may depending on the file's size) but instead just reading in whatever your buffer size is. You can choose to only read in only so much at a time (hence the size_t arg for recv).

I don't know what you mean regarding "point the program to the direct link". Are you asking if the SPRX can just take a link to the file and download it like that? If so, not easily from what I experienced. This was just the easiest way I found to do it.
07-31-2017, 12:39 AM #7
Tustin
Balls of Steel
Originally posted by Smoulougde View Post
Ok i see, thanks for the reply. I will try the function in php soon for files of my menu (ini / txt and sprx) Smile


Sorry, ignore what I said about the response header/body. For some reason when I replied earlier I was thinking this was using HTTP requests. The buffer size should be a length of bytes you're comfortable storing at one time. Setting it to 1024 (or 1 KB) should be sufficient. That basically means the socket will read 1 KB of your file each time and store that in the file.
07-31-2017, 08:18 PM #8
Originally posted by Tustin View Post
The server socket will serve all of the bytes of the file but the client socket isn't necessarily reading it all in at once. It's not reading in the whole file (well it may depending on the file's size) but instead just reading in whatever your buffer size is. You can choose to only read in only so much at a time (hence the size_t arg for recv).

I don't know what you mean regarding "point the program to the direct link". Are you asking if the SPRX can just take a link to the file and download it like that? If so, not easily from what I experienced. This was just the easiest way I found to do it.


Ah now I see what you're doing there, didn't think about that, but I got it now.

And right, exactly that, hmm, don't see why there'd be a hassle there, can't you just request the file through socket then write them to disk?

The following user thanked John for this useful post:

Smoulougde
07-31-2017, 08:24 PM #9
Tustin
Balls of Steel
Originally posted by John View Post
Ah now I see what you're doing there, didn't think about that, but I got it now.

And right, exactly that, hmm, don't see why there'd be a hassle there, can't you just request the file through socket then write them to disk?

I tried, but I'm not experienced enough with HTTP requests/responses to try to do it like that. It's probably possible, but this is the only way I knew how to do it at the time.
08-01-2017, 02:36 PM #10
Smoulougde
S.P.E.C.I.A.L
Originally posted by Tustin View Post
Sorry, ignore what I said about the response header/body. For some reason when I replied earlier I was thinking this was using HTTP requests. The buffer size should be a length of bytes you're comfortable storing at one time. Setting it to 1024 (or 1 KB) should be sufficient. That basically means the socket will read 1 KB of your file each time and store that in the file.


Ok i understand now.

Just 2 questions, in DownloadFile(char* ip, const char* fileName)
For ip, i put the IP of my website, but for fileName i put the position of file where i want save file downloaded ? So it's /dev_hdd0/tmp/GTA.sprx for example ?

And after, in php coding. You put "Tesseract.sprx", this file is placed in root folder of website right ? So i can edit, for send the file contained in folder like this You must login or register to view this content. ?

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo