What to learn to be able to send files online using c++ on windows? - c++

What to learn to be able to send files online using c++ on windows ?
i know c++, and i got a program that does some benchmark and saves into a text file, i want that text file to be sent to me after the benchmarking is done, so what should i search for ? tried searching found something called sockets and something about server and clients in linux, kinda dunno what to search for.
this isn't a homework, just want to do it for fun xD, and would help me in future if i want someone who knows nothing about whats happening to test something for me (the file would have all i need and it will be sent to me).

I think you better off just emailing the file after a benchmark is done, and doing it using some bash or Python scripting rather than C++ or any other low level language. Here is an example of sending email using Python. Another option would be to upload to the FTP or use rsync to transfer file over SSH. And in any case, do not write your own client-server application for this.
If you still want to use C++, here is an example of sending email using POCO.

you will find some official documentation on Win32 sockets here:
http://msdn.microsoft.com/en-us/library/ms738545%28v=vs.85%29.aspx
This tutorial seems pretty good and simple:
http://johnnie.jerrata.com/winsocktutorial/
Have a nice day!

Related

Best way of logging a user in C++

I am trying to get into C++ programming so apologise if this is a bit of a stupid question.
I am attempting to create a program in C++ that is linked to a website via the database, that's all sorted. In this program, the user must log into it to be able to use its features, I've also managed to do this fine. My question is, what is the best way of storing that users session so I can refer to their username, display that users settings from the database e.c.t?
I am unsure, but I don't think c++ has session options like in php so I cannot do it that way. I did some googling before I posted this, spent all night trying to find a solution, I found nothing.
My knowledge if c++ is slim and this may sound like a more complicated or unnecessary route to take, but it was thinking of perhaps when the user logs in, to create a txt file storing that users username and then calling on it when I need to refer to that users username for queries and such, then when the user logs out or closes the program it deletes the file. Is that stupid? Forgive me if it is.
Is there better way to go about this?
Thanks for your time!
EDIT
I read your comments, if it needs to be a stand-alone application, like some sort of client, you could take a look at the C++ libraries I mentioned, but I'd use any higher level language (Java or C# have good documentation and there are many tutorials for creating GUIs, if that's what your're looking for. I think even Python would make a good candidate).
If you really must use C++, your best bet would be to use an existing library to implement your web solution. POCO includes an HTTP server framework, and a library for sockets and other forms of low-level network programming. Boost ASIO can also serve your purposes. But this is hardly something I'd recommend to start learning programming, or C++ for that matter.
If you want to learn about web programming, then you should definitely take a look at other languages. PHP or ASP.NET come to mind. AS you learn, you'll most likely also end up writing some form of Javascript. You can find a lot of info out there, just Google for tutorials. A site to get started is w3Schools, but any site with tutorials will do. Good luck!

Using networks in c++

I have started learning c++ quite a while ago, and I am now starting to develop a program which uses a Chat file like this:
filename: (identity):(date)
contents: (identity):(message)
But the only problem I have is that I need to access and send this file over a network(A LAN created using Hamachi).
Do I need several libraries or something for this?
Can anyone give
tips on how to achieve this?
There is a lot of libraries which can help you:
very powerful from boost:
http://www.boost.org/doc/libs/1_48_0/doc/html/boost_asio.html
one from QTNetwork (ofc if you are using QT).
I recommend you to do not use Winsock etc you will be limited to a one platform only.

Remote interop with OpenOffice Writer

I found some documentation about interop with OpenOffice using technologies like COM, but before delving in more deeply I wondered if anyone's worked on this kind of thing?
We have a need for the following, all wrapped up in a method call from a client PC (client talks to server using COM):
Client sends a map of name/value pairs to a server app
Server opens a Word template (.dot currently) file and looking up bookmarks using names from 1, replaces the text with values
Server saves file as a Word .doc file
We were doing this using Word but some changes in Windows 2008 mean if you run without a desktop/interactive-user, Word won't start. It's obviously a big hack but we're looking for a quick solution rather than re-engineering due to time constraints... so I wondered if we can simply run up OO Writer on the server to do the same job? I know how ugly it all is so don't really need suggestions to create a brand new C# open XML SDK application.
Multiple simultaneous requests can be ruled out as a potential problem (or at least it's never been a problem using Word so unless OO is different it'll be ignored).
If you are thinking OpenOffice might help, you could use JODReports or Docmosis to help, though you'd need a small Java program to bridge from your C++ app (cmd line or whatever). These tools will let you control OpenOffice a little easier for doing your merge task than working with the OO API directly (hopefully a lower learning curve).

Any way to display C++ on a webpage?

Is there a relatively easy way to display the output of a C++ program on a webpage? And I don't mean manually, in other words, you see it on a webpage as it runs not as in I make a code tag and write it in myself.
EDIT: Just so everybody can get this clear I am going to post this up here. I am NOT trying to make a webpage in C++. Please excuse me if this sounds spiteful or anything but I am getting a lot of answers relating to that.
Step one, get yourself a server-side language. Be that PHP, ASP, Python, Ruby, whatever. Get it set up so you can serve it.
Step two, find your language's exec equivalent. Practically all of them have them. It'll let you run a command as if it were from the command line, usually with arguments and capture the output. Here's PHP's:
http://php.net/manual/en/function.exec.php
Of course, if you're passing user-input as arguments, sanitise!
I've just seen that you accepted Scott's answer. I usually wouldn't chase up a SO thread so persistently but I fear you're about to make a mistake that you'll come to regret down the line. Giving direct access to your program and its own built-in server is a terrible idea for two reasons:
You waste a day implementing this built-in server and then getting it to persist and testing it
More importantly, you've just opened up another attack vector into your server. When it comes to security, keep it simple.
You're far better having your C++ app running behind another (mature) server side language as all the work is done for you and it can filter the input to keep things safe.
You could write a CGI app in C++, or you could use an existing web server language to execute the command and send the output to the client.
You want to use Witty.
Wt (pronounced 'witty') is a C++
library for developing interactive web
applications.
The API is widget-centric and similar
to desktop GUI APIs. To the developer,
it offers complete abstraction of any
web-specific implementation details,
including event handling, graphics
support, graceful degradation (or
progressive enhancement), and pretty
URLs.
Unlike many page-based frameworks, Wt
was designed for creating stateful
applications that are at the same time
highly interactive (leveraging
techinques such as AJAX to their
fullest) and accessible (supporting
plain HTML browsers), using automatic
graceful degradation or progressive
enhancement.
The library comes with an application
server that acts as a stand-alone web
server or integrates through FastCGI
with other web servers.
I am not sure this is what you are looking for but you may want CGI You may want to look at this SO question, C++ may not be the best language for what you want to do.
based off the questions you posted Writing a web app like what you want is no simple task. What I would recommend is use some other library (this is one i found with a quick google) to get a web console on your server and give the user it is running under execute deny permissions on every folder except the folder you have your app installed.
This is still is a risky method if you don't set up the security correctly but it is the easiest solution without digging around too much on existing libraries to just have the application interactive.
EDIT --
The "Best" solution is learn AJAX and have your program post its own pages with it but like I said, it will not be easy.
It sounds like you want something like a telnet session embedded in a webpage. A quick google turns up many Java telnet apps, though I'm not qualified to evaluate which would be most ideal to embed in html.
You would set up the login script on the host machine to run your c++ app and the user would interact with it through the shell window. Note though that this will only work for pure command line apps. If you want to use a GUI app in this way, then you should look into remote desktop software or VNC.
It may be worth looking into Adobe's "Alchemy" project on Adobe Labs
This may help you with what you're trying to achieve.
:)
Are you looking for something like what codepad.org does? I believe they explain how they did it here.
There is a library called C++ Server Pages - Poco. I used it for one of my college project, its pretty good. There is also good documentation to get started with, u can find it here http://pocoproject.org/docs/

C++, Get text from a website

I was told I have to use winsock, but I dont know where to start. For example, I am trying to access, lets say http://www.newegg.com/, I am trying to get the text title of just the three front page products. Any help is greatly appreciated. :D
I'd also recommend libcurl for this sort of thing.
You can use the cURL command line tool to generate sample code as well, which is helpful for experimentation.
W3.org themselves provide sample C / C++ librarys for Http requests.
Find them here
Specifically, look for HTTPReq.c
Use boost library and poco. They both provide solutions for network programming. Boost also provide spirit library which you can use for parsing data from websites. Poco libraru also provides NetSSL, crypto solutions.
P.S. boost::spirit is not a library for parsing data from websites, it provides solution for parsing strings ...
you need to open a socket.
then you need to do an http get
somewhat like :-
http://www.esqsoft.com/examples/troubleshooting-http-using-telnet.htm
You could use the QNetworkAccessmanager class from Qt framework.
I'm assuming you need to use c++ for a reason, such as integration with existing software, otherwise, as per some of the other suggestions, choosing a language with a more convenient framework (eg: scripting language) would be better suited for the task.
If you would like to avoid getting your hands dirty with WINSOCK, or have the need to run on a platform other than windows, you could look at the using the boost asio library.
The following page contains links to simple sync and async http clients:
http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio/examples.html
You can find documentation on the library itself at:
http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio.html
Use c++ if you must, but it might be a lot less painful to use python.
Look at the Python httplib module for how to set the host you want to pull from etc. Python's available for free for most platforms and is enough like C++ that you can probably learn python a heck of a lot faster than you can learn to write a program controlled browser in c++. Well, maybe that's not true for everyone on this site, but I'll bet it's true for "most" of us. I used to get stock quotes updated in near real time from CNN Money years ago and IIRC it was around 100 lines of python code.
Hotei