THREAD: File Downloader Code (For SPRX)
  1. 07-24-2017, 10:30 PM
    Tustin's Avatar
    Tustin
    Balls of Steel
    Tustin's Avatar
    Tustin
    Balls of Steel
    5,462
    Posts
    310,606
    Reputation
    May 2008
    NextGenUpdate
    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.

  2. The Following 2 Users Say Thank You to Tustin For This Useful Post:

    ,

  3. 07-30-2017, 02:25 PM
    Smoulougde's Avatar
    Smoulougde
    S.P.E.C.I.A.L
    Smoulougde's Avatar
    Smoulougde
    S.P.E.C.I.A.L
    403
    Posts
    5,883
    Reputation
    Mar 2015
    NextGenUpdate
    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 ?
  4. 07-30-2017, 05:35 PM
    Tustin's Avatar
    Tustin
    Balls of Steel
    Tustin's Avatar
    Tustin
    Balls of Steel
    5,462
    Posts
    310,606
    Reputation
    May 2008
    NextGenUpdate
    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.
  5. 07-30-2017, 08:52 PM
    Smoulougde's Avatar
    Smoulougde
    S.P.E.C.I.A.L
    Smoulougde's Avatar
    Smoulougde
    S.P.E.C.I.A.L
    403
    Posts
    5,883
    Reputation
    Mar 2015
    NextGenUpdate
    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
  6. 07-30-2017, 09:43 PM
    John's Avatar
    John
    skid
    John's Avatar
    John
    skid
    1,822
    Posts
    65,814
    Reputation
    Dec 2012
    NextGenUpdate
    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?
  7. 07-31-2017, 12:35 AM
    Tustin's Avatar
    Tustin
    Balls of Steel
    Tustin's Avatar
    Tustin
    Balls of Steel
    5,462
    Posts
    310,606
    Reputation
    May 2008
    NextGenUpdate
    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.
  8. 07-31-2017, 12:39 AM
    Tustin's Avatar
    Tustin
    Balls of Steel
    Tustin's Avatar
    Tustin
    Balls of Steel
    5,462
    Posts
    310,606
    Reputation
    May 2008
    NextGenUpdate
    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.
  9. 07-31-2017, 08:18 PM
    John's Avatar
    John
    skid
    John's Avatar
    John
    skid
    1,822
    Posts
    65,814
    Reputation
    Dec 2012
    NextGenUpdate
    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?
  10. The Following User Thanked John For This Useful Post:


  11. 07-31-2017, 08:24 PM
    Tustin's Avatar
    Tustin
    Balls of Steel
    Tustin's Avatar
    Tustin
    Balls of Steel
    5,462
    Posts
    310,606
    Reputation
    May 2008
    NextGenUpdate
    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.
  12. 08-01-2017, 02:36 PM
    Smoulougde's Avatar
    Smoulougde
    S.P.E.C.I.A.L
    Smoulougde's Avatar
    Smoulougde
    S.P.E.C.I.A.L
    403
    Posts
    5,883
    Reputation
    Mar 2015
    NextGenUpdate
    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. ?