Thread: Client-servers transfers, running scripts and sending it all back...

  1. #1
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665

    Client-servers transfers, running scripts and sending it all back...

    Hey guys,

    Okay, let's say that I want to design a website feature. The client chooses a set of files that are transferred to a server. This is supposed to be a read-only operation.

    Once the server has the files, it needs to run an ant script which generates a PDF from the transferred files.

    Once the ant script has completed, I need to email the resulting PDF back.

    I know next to nothing about this kind of stuff so I'm really just fishing for tools I should use here. I was thinking about doing the client-side stuff in HTML + Javascript (the new File APIs are nice) but I'm not sure how I'm supposed to do the server side stuff.

    So here's my basic notes :

    * Server needs to be in a constant state of waiting
    * Need to know when files are being transferred
    * How to make the server wait and then execute the ant script

    I'm assuming I can just rent out a server that has Linux on it and install everything I need to.

    But do I use Node.JS? If so, how do I use Node.JS and then ant stuff? I feel so lost...

  2. #2
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Okay, I found this resource and so far it looks amazing (I haven't yet tested it) : Uploading Files with AJAX | Treehouse Blog

    But the one thing I'm really having trouble figuring out how to do is this the part they mention at the bottom of the blog : <quote>That’s everything you need to know to start uploading files using AJAX. Your server-side code will need to extract the files from the request and process them as desired.</quote>

    How do I write the server-side code?

  3. #3
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    Quote Originally Posted by MutantJohn View Post
    How do I write the server-side code?
    Your best bet is to write a CGI script in Perl, Python, PHP, Ruby, or Lua. Just about every single hosting provider I've looked at supports PHP, and this task is quite straightforward using PHP. The script would be run under the web server, typically Apache or Nginx, with the server provided by your hosting provider.

    However, I would recommend doing the conversion synchronously instead. I don't mean abandoning AJAX, I mean not having a separate script on the server that does the conversion, but have the upload script perform or run the conversion script, as part of the upload process. It does not really matter whether you send the resulting files via e-mail, or link or embed to a result page (the URL you can provide as a return string from the AJAX upload query). Most providers do not like daemonized scripts (that is, non-CGI scripts) running on their web servers, so doing the conversion as part of the upload process is more in line with most service providers' rules. Execution time and memory use limits do still apply, so it all depends on exactly what the conversion requires.

    (There are also PDF libraries for producing PDF files from PHP and Python. If you could replace your Ant scripts with PHP or Python script, it might make it much easier to get your service and scripts hosted on a cheap-but-good hosting provider. There are a few good ones (not skimpy with server resources), but their installations do not tend to have all the frills and whistles; the fewer external requirements your scripts have, the easier it is to get them hosted.)

    As to the PHP code, w3schools.com has an example. If you prefer Python, here's an example. There are many examples for any language you prefer; just look for cgi file upload and the language.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I'd use ASP.NET instead of PHP/Python if possible, because frankly, those languages suck last time I looked (no type safety, no RAII-style cleanup of resources are among the most glaring omissions I know of).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by Elysia View Post
    (no type safety, no RAII-style cleanup of resources are among the most glaring omissions I know of).
    In python, no type safety means you can write 'meta' code effortlessly.

    And there is a keyword 'with' that provides RAII 'blocks' in a structured way.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by manasij7479 View Post
    In python, no type safety means you can write 'meta' code effortlessly.
    It also means the rest of your code will be very buggy and you have to make a lot of efforts to properly test the code that the compiler would normally do for you.

    And there is a keyword 'with' that provides RAII 'blocks' in a structured way.
    That's awesome. Good work, Python!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    PHP all the way. It just works.

  8. #8
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by Elysia View Post
    It also means the rest of your code will be very buggy and you have to make a lot of efforts to properly test the code that the compiler would normally do for you.
    Always the practitioner of disinformation, aren't you Elysia? It's just not your ignorance that shows to anyone knowing better. That alone would be fine; I don't care for you personally. It's just that you use your ignorance as a way to influence others. And that bothers me...
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  9. #9
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by Mario F. View Post
    Always the practitioner of disinformation, aren't you Elysia? It's just not your ignorance that shows to anyone knowing better. That alone would be fine; I don't care for you personally. It's just that you use your ignorance as a way to influence others. And that bothers me...
    O_o

    ---------------------------

    But man, this whole web coding stuff is really tough. This is going to be my second day studying this stuff so hopefully it goes better.

    Out of curiosity, does anyone know of any server service that's good? I'm assuming I need to pay for it but what I need is, is complete control over my own little portion of it. I need the ability to install programs, host websites, run scripts, etc.

    Right now, my mommy is just using a web hosting service for the website itself. I'm not sure if we're allowed to go in there and be like, I'm going to install Java + other things.

  10. #10
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by MutantJohn View Post
    Out of curiosity, does anyone know of any server service that's good? I'm assuming I need to pay for it but what I need is, is complete control over my own little portion of it. I need the ability to install programs, host websites, run scripts, etc.
    You'll need a web hosting service that offers you a Virtual Private Server package, aka VPS. There's plenty of them and today any web hosting service worth its salt, will have one or more VPS offerings.

    As for a good, that's tricky. I personally work with A Small Orange and have been very happy with them for the past couple of years.

    Meanwhile you may also want to know that there's a better graded service called Dedicated Private Server. Unlike a VPS, a DPS doesn't run on your own virtualized operating system inside a machine sharing multiple virtual OSes. A DPS means you'll have your own dedicated machine. No virtualization.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Mario F. View Post
    Always the practitioner of disinformation, aren't you Elysia? It's just not your ignorance that shows to anyone knowing better. That alone would be fine; I don't care for you personally. It's just that you use your ignorance as a way to influence others. And that bothers me...
    This is not disinformation. This is from my own experience with Javascript some years ago. It really makes you appreciate strongly typed languages.
    But not only that - I've made several mistakes and created several bugs which could have easily been resolved had I just used stronger typing. The compiler picks up the bugs for you! And that is the next best thing to static analysis which often is very expensive and computationally long.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    This is not disinformation.
    O_o

    It also means the rest of your code will be very buggy and you have to make a lot of efforts to properly test the code that the compiler would normally do for you.
    You presented that comment as a statement of fact.

    You complained that Python code is necessarily very buggy.

    You implied that Python code was necessarily more buggy than code written in other languages by someone of similar experience.

    You are wrong; you did present disinformation.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by phantomotap View Post
    You presented that comment as a statement of fact.
    You should know that the line blurs between facts, experienced facts and opinions on a net forum. These are facts as I know them. These are not general facts and not necessarily "facts" that someone knows.

    You complained that Python code is necessarily very buggy.
    You implied that Python code was necessarily more buggy than code written in other languages by someone of similar experience.
    Alright. Let me reword that.

    I am implying that where we have similarly written code between Python and other languages with people with equal experience, the Python code will be buggier than a strongly typed language before properly testing it (and yes, it could even still be buggier than strongly typed languages; the whole mars crash incident is proof enough).
    The biggest problem I have is the extra time you have to spend testing the code which the compiler would have done for you in a strongly typed language. Why should we spend that time testing the code for silly bugs when we could spend that time doing something productive instead?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    So, I've been using Apache and XHTML + PHP on my home machine and I really like it so far. I've learned how to upload files to the server and now I'm learning checkboxes. Thank you for your aid, you guys!

    I'm learning an exciting new branch of programming. I can actually make web stuff now!!!!

  15. #15
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Okay, one question though and this is a Javascript thing.

    I'm trying to create a checkbox hierarchy.

    Basically, we have a base set of checkboxes. Each time a box is checked, a sublist of checkboxes is appended to it directly. When it's unchecked it'll collapse but I'm not at this stage of development yet.

    So far, the only way I know how to do this is using onclick events for my HTML <input type="checkbox" onclick="some_js_function()">

    My idea was to somehow map the files in a tree structure. Each file has associated children, basically. I want to use a nodal structure containing the filename and its associated children.

    My biggest question is, assuming all these nodes were allocated correctly, how do I keep them persistent throughout the lifetime of the HTML? So far, Javascript is only invoked with an onclick event which I'm assuming means that allocated tree structure will be freed once the script is completed. So, how can I avoid costly reallocations of my data?

    This isn't important now but it's a glaring performance hit.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function not sending back values
    By Sal Zaydon in forum C Programming
    Replies: 2
    Last Post: 11-05-2013, 07:37 AM
  2. Replies: 0
    Last Post: 03-12-2011, 02:10 AM
  3. intercepting packets for web servers and replying back
    By liri in forum Networking/Device Communication
    Replies: 1
    Last Post: 10-21-2007, 10:43 PM
  4. 1 client, 2 servers
    By maxorator in forum Networking/Device Communication
    Replies: 3
    Last Post: 10-04-2006, 08:59 PM
  5. any good Tutorial about building Servers/Client
    By Bug in forum Windows Programming
    Replies: 1
    Last Post: 06-26-2003, 04:48 AM