I'm trying to write a C++ component to upload a file on a FTP server through a FTP proxy (specified by host/port/user/password).
In a first time I tried using Qt (QNetworkAccessManager/QNetworkProxy) but for an unknown reason it does not work (when I try to upload the same file with FileZilla using the same connection parameters, it works). My code also works when I have no proxy.
In a second time, I tried with libcurl but it seems this lib does not support FTP proxy.
Any suggestion of another C++ lib I could try? or a Win32 (winsock) example?
If you're targeting Windows, you can try using the Windows Internet APIs to implement the FTP client. I'd imagine you'll have an easier time using them rather than manually implement an FTP client atop sockets.
I haven't looked at them, but there seem to be a few samples here.
Related
I would like to let my C++ program get some data from an HTML page. Is it possible to use HTML5 local storage for this purpose? Is there an accessible file generated by the browser?
If this is not feasible in this way, are there any other options?
For now the browser and my executable run on the same computer, and I would prefer to only use the fstream C++ library.
The most appropriate communication channel would probably be FCGI (http://www.mit.edu/~yandros/doc/specs/fcgi-spec.html). You would need to set up a local HTTP server and configure it to process specific HTTP requests using your FCGI-compliant C++ application. Modifying your C++ application to support the FCGI protocol may be non-trivial, but the protocol itself is simple.
Here is a useful article detailing how to get started:
http://chriswu.me/blog/writing-hello-world-in-fcgi-with-c-plus-plus/
I'm developing a Windows intranet application in C++ which needs to download a settings file from a predefined URL hosted on a webserver on the intranet.
This file would be updated every few weeks and I need to get it only if it has changed.
To avoid unnecessary downloads I wanted to know if there is a standard HTTP method to only request the hash of the file to the webserver to prevent a full download if the file has not changed.
I'm still in the design phase and the idea would be to use CURL library on the client to download the file and Apache as a webserver, but I'm also open to other solutions.
I'm building a C++ application that produces data that I want to pipe to a web browser. If I send all of the data to the server, and then out to clients, there will be too much traffic. Is there a way I can use my server to establish a direct socket connection between my C++ application and a remote browser?
I'm writing my server using node.js for what it's worth
Yes: you can embed a web server inside your C++ application. If you can poll for the data using simple HTTP GET, you can use the simple C web server library "mongoose" for example. Or you may need to use WebSockets which probably requires a fancier library in C or C++. Then your Node.js server can simply give the URL of your C++ server to the clients, who will connect to the C++ server directly.
All that being said, it's likely that Node.js can support the load, so if you haven't actually run into scaling problems, you might want to just skip this whole project.
I have javascript (client - executed through node.js) and C++ (server) code running on Ubuntu (Linux) and I want this client-server to communicate with each other. Can somebody tell me how I can make C++ code work like a server or client using web socket? Basically, I want javascript code to send some data to C++ code, the C++ code will process on the data and return the result back to javascript code. I'm not sure if I this communication between javascript and C++ code can happen with out web socket. Any pointers in this direction would be of great help!
Thanks,
pats
I very recently started working on a C++ websocket library: https://github.com/szmoore/foxbox
An example of a websocket server is: https://github.com/szmoore/foxbox/blob/master/examples/wsserver.cpp
I also have an example of a JavaScript client.
Warnings: The library doesn't support TLS, is based around POSIX sockets, and is still in development and probably horribly insecure.
So, whilst shamelessly promoting my own library I will also point you at libwebsockets, a C library suggested in answer to this question: https://stackoverflow.com/questions/3916217/standalone-c-or-c-websocket-server-library?lq=1
You have several choices. I am assuming your C++ server already has a websocket server running on it but if not, get Mongoose or the non-GPL fork Civetweb. Both are tiny bits of c code you build into your C++ program to add webserver,including websockets, functionality.
In fact, civetweb comes with a websocket example.
However, you do not need a websocket, just an ordinary socket should do. You'll probably want to send the data in JSON format to makeit easy to consume by the javascript code.
I know this question was asked a LOOONG time ago, but here is a gist of my set up that allows to have a communication between my c++ and Javascript apps; if anyone stumbles on this question:
I use TCP/IP connections to set up communication between a C++ app and a Javascript (Typescript) app. ZeroMQ (0mq) library is perfect for that. On c++ side you have libs like zmqpp and on the JS side you have zeromq.js.
After the data is received in JS land, you can use Socket.IO if you would like to have that streaming data available in a browser. Generally, you would have to forward the data stream off 0mq through Socket.IO and then access it on the browser side.
Bonus: make the data format using Protobuf.
On the Javascript side you will probably want to use an XmlHttpRequest. This will cause the javascript to post an HTTP(s) request to your server. For the C++ server side, you can look at something like Pion for an embeddable HTTP server or if you want to link into a full web server like Apache, you can use Fast CGI to plug your server code into Apache.
I need to build a lightweight http server for my application basically it's a server which listen to a port and outputs a status information on requests, https, other functionality. But I would like to know first if something like this existe in C++, for linux and open source.
Does anyone know a program like that?
Thanks.
EDIT: It should be able to support high load.
If you can use boost, the asio library provides an http example. It does not use SSL, but asio can use OpenSSL very easily.
If you want to handle high loads I would suggest following:
Use proper web server with all goodies it comes with like Lighttpd, Nginx or Apache (in that order).
It would do great job in serving static files and handle your application. And they are very lightweight.
Write an Application in C++ using proper web framework - CppCMS - that is designed for high loads
Connect Web Application to the server via FastCGI or SCGI protocol (in this order).
Disclaimer: I'm the author of CppCMS
A quick google search for "C++ web application framework" shows things called CppCMS and something else called WT. That might get you started.
Or, as Sam already answered: boost.asio comes with a HTTP example that may be sufficient if your needs are simple. (Real HTTP request handling is actually surprisingly complex: http://webmachine.basho.com/diagram.html )
See thttpd. Supposibly the fastest open source file server on all machines with a single CPU.
If not using HTTPS, it's about a two hour exercise to write a static file server.