I am looking for an HTTP library for C/C++, that handles only the protocol logic, instead of the actual transport mechanism. Libraries I've came across tend to incoperate the entire communication process, which is not what I need.
However, I'm looking for something that's more than merely an HTTP parser. Ideally it would also take care of things such as session/connection management, multiplexing, etc... only that it would leave the actual implementation of the communication details for application to perform. I'm looking at both client and server ends, though any of them would be helpful.
Preferably I'm looking for something that's free (non GPLed, though). HTTPS is a plus. Lightweightness is a plus. Simplicity is a big plus.
Anything like this?
I think the best thing you are going to find is one that implements it in a well separated manner. An HTML Server without a socket implementation is useless to most of the world. I would look for well separated code. Here is an example of a very minimalistic html server that seems it may be well separated, not completely sure, as I have not tried it myself, but you could replace the socket classes with your own implementation and wrappers, and do it that way.
http://www.adp-gmbh.ch/win/misc/webserver.html
There may be other examples out there as well. A good google search may be your friend here. At any rate, I don't think you are going to find a totally disconnected server and client that is totally abstracted from the socket implementation(s) that they use. I've had to do this myself before, to write an html client that did not use sockets, but used serial io to another device, that would pass the data through onto the wider internet.
The problem is that once you want it to do session management, it's a LOT simpler to write the library to include the transport (usually sockets) handling directly, rather than try to define a usable interface that the application can implement to do the underlying transport work. Especially since most (obviously not all) users need both components anyway.
If you want a subset of a web-server read the source-code of an open-source server and strip out what you don't need. You might want to look at lighttpd and nginx. They are simple lightweight web-servers.
libsoup seems to do what you described. neon is close.
session/connection management
libsoup: soup_session_sync_new()
neon: ne_session_create()
multiplexing
I'm not sure what exactly you mean. whould you mind to enlighten me?
leave the actual implementation of the communication details for application to perform.
libsoup: soup_message_headers_foreach() and soup_message_body_flatten()
neon: no public API (would be nice to have build_request() as public)
both client and server ends
libsoup: client and server API
neon: client only
free (non GPLed, though)
libsoup: LGPL
neon: GPL
HTTPS
libsoup: yes
neon: yes
Lightweightness is a plus
it depends
Simplicity is a big plus.
it depends
Related
On the server side, everything is ok.
But on the client side, it seems we cannot just use Thrift to process the protocol, and send/receive the data by using our own I/O framework(such as muduo or other ones).
Is there any way to implement this with C++?
I think this is a legitimate question, and it can be extended to the more general question:
How do I use other transport mechanisms with Apache Thrift?
As Hcorg pointed out, because of ist modular structure of the framework, it is not quite hard to achieve that. Basically, one has to follow these steps (this is true for all languages supported by Thrift, not only C++)
derive a specialized class from TTransport. In some cases this is an interface, not a base class, but that does not really matter.
implement all the methods needed
for the server side, you may need a TServerTransport derivative
The existing implementations may serve as models, and despite the number of methods in TTransport, most of them are not really hard to implement.
Additionally, I also provided a specialized transport implementation to use STOMP with Delphi, based on a TStreamTransport. The relevant code can be found in the /contrib Folder and is worth a look. You know, one of the nice things about Thrift is that stuff work very similar in all languages.
I'm writing a distributed system wherein each node interfaces with local applications via some RESTful API, supports extensions and runtime customization, etc. It's a bit like an Enterprise Service Bus over the wide area, but with a lot else going on which is not related to the question at hand.
I've read a little about both MPI and Asio - originally I was set on Asio, but then I found MPI, and now again I'm thinking Asio is the better solution for me. MPI seems to provide a lot I don't need and a higher level of abstraction than I want - for example, I only need point-to-point communication, and it is important to me to be in control of when and what data is transmitted. (e.g. I have already designed a packet structure that I would conform to ideally)
So my primary question: it is worth it to start from a lower level with Asio, or should I try to graft MPI onto what i'm looking for? Further, are there 'skeleton applications' available which use MPI or Asio which would aid development? (Actually I am 100% new to C++.. ;) Or, does it make sense to use them in tandem?
For more perspective, maybe it's worth noting that I already have implemented the bulk of this project in Perl using Perl Object Environment, which itself is just an asynchronous event system with a ton of networking libraries.
Also, if it makes a difference, I would ideally use threads for this.
Honestly though I have not used Boost at all yet, as I hinted above, so any input is appreciated.
I should start by saying that I know nothing about Asio, but from the 2 minute scan of the website and the description of your problem, it sounds like while either would probably work for you, Asio might be simpler. MPI is really designed less for general purpose network communication and more for running applications where the set of processes and applications is a little more static. While it provides a client/server style interface if desired, it's not the main focus of the library.
MPI is also more difficult to use if you already have a packet structure designed. MPI is great for abstracting away the need to worry about packets, location of processes, etc. but if you've already taken all of that into account in you application, you have already done the hard work.
There have been at least one other discussion of Asio vs. MPI that you can take a look at (For distributed applications, which to use, ASIO vs. MPI?) to get more opinions too.
I want one application on a linux host to call procedures from applications on Win7x64 in a VM. I guess that the VM runs on the linux host does not matter since it should use sockets. How do approach this plan? Are there any libraries for that in the internet?
Edit:
Well I took am look at all of them. XMLRPC seems to be some kind of predecessor of SOAP. Prototbuf seem to me like having the focus on easy serialization of large objects. So my decision falls on SOAP. But now I am searching for a nice-to-use c++ binding. I read a few pages of the apache axis2 manual but its everything else but nice-to-use, and anyway in C.
Another question in my specific case is: Isn't it easier to send just send some textual numbers plus parameters to identify the procedures to call and reply in textual form, as I know the signature of the called procedures?
Edit2:
As SOAP is just a standard and RPC is just curious, (Imagined something like function pointers over IP :D) ,imho none of them all is a solution. But ZeroMQ is indeed a progress.
There is no magic to RPC. I would suggest having a look at a combination of ZeroMQ and Google protobuf. ZeroMQ is a very easy to use messaging system (your communication layer). You would use the REQ/REP pattern. Google protobuf is used to describe and serialize/deserialize your messages. Both libraries are cross-platform and even cross language (ruby, python, c++, etc. etc.)
Have you taken a look at SOAP? It has pros and cons but may meet your needs.
The fact that your Windows box is VM shouldn't make a difference providing that it's up and running, and so long as the system you choose treats the servers as logically separate sockets normally would, your solution will remain flexible.
One decent alternative is XMLRPC, which runs on top of HTTP. It's simpler than SOAP, at least. I've used it for Java-Python communication, and it was not much code then, but don't know any C++ libraries to recommend, so I'll just say http://en.wikipedia.org/wiki/XML-RPC and its C++ section to that.
Edit after edited question: For a really simple solution, just use plain HTTP, mapping request path to function and giving parameters with GET or POST. Return value in HTTP response data as simply as you can: plain text for number or string, for more complex return value a binary blob if binary compatibility can be ensured (same CPU, same word size, plain struct, using compiler struct packing options if needed), or as json (or even XML, but then you are starting to reinvent SOAP/XMLRPC...).
Is it possible to exchange web-services over socket programs written in C/C++?
The data to exchange are in the from of xml/soap message.
Yes, it is possible. You can write code that uses standard POSIX sockets, so it will be portable between windows and unix-like operating systems. But you'll very likely want to build up some layers of abstraction to make it all easier on yourself, or use an existing library.
As for talking to webservices, you will need some sort of XML/Json/whatever parser. SAX is a good XML parser, and I'm pretty sure there is a C interface for that. But it all depends on the data format.
http://www.securitytube.net/Socket-Programming-Basics-Presentation-video.aspx
If you're using web services, you'll spend more time writing socket code than you will writing code to consume the web services.
If it is SOAP web services, use gSoap (http://www.cs.fsu.edu/~engelen/soap.html). If it is something like REST web services or plain data exchange over an HTTP post without all the SOAP protocol stuff, libcurl (http://curl.haxx.se/) is easy to use too.
Both libraries will work on Windows and Linux.
Put simply, yes. I suppose you likely want more detail than just a "yes", but the question is far too general to garner any much more specific answer.
You mention UDP and even raw sockets, but it's not clear to me why. "Web Services" are typically HTTP, which means they're over TCP.
I think at this point in your learning there are just far too many things for you to learn that it sounds like maybe you just don't even know the questions to ask. Perhaps if you could be more specific about what you're trying to accomplish folks could provide more helpful answers.
Maybe you want to try CGI? With it it's possible to create a website in C++, without worrying about sockets.. Your compiled executable will be executed by the web server every time a page is requested, and the output of said executable will be sent to the web browsers.
So you can do stuff like cout << "<html>";.
[I know that this is not exactly what you asked but your question isn't very clear, and I didn't want to repeat something already said!]
What is the best way to use sockets on the Windows platform?
Basic sockets I guess, TCP/IP.
Maybe for a chat client, or just for learning.
Could someone give me an example of WININET usage?
maybe ftpgetfile()
That is a very broad question, and depends a lot on your needs.
What level do you need? HTTP/FTP? Or "just sockets" for your own protocol? What kind of performance do you need (amount of connections, expected speed)?
If you choose to go raw API, you should generally stay away from WSAAsyncSelect since performance is abysmal above "a few" concurrent connections. Blocking sockets and thread-per-socket isn't too hot either. WSAEventSelect is slightly tricky, but gets the job done nicely (µtorrent handles a lot of concurrent connections this way). Fancypants really-high-load would be I/O Completion Ports. You could also look into boost ASIO for some portability.
If you want to use standard protocols like HTTP/FTP, check libcurl. Or, for lesser needs and smaller overhead, the standard Windows WININET functions (has a lot of restrictions though).
For using WinINet functions, try starting here - might not be a sample, but at least gives you enough stuff to google for ;)
For basic client server application with TCP/UDP winsock should be sufficient.
Do you mean asynchronous I/O model on windows?
There are select, WSAAsyncSelect, WSAEventSelect, Overlapped I/O, I/O Completion Port, also you may want to use Libevent and Boost Asio which are both cross platform.
WinInet examples you could find in msdn or codeproject.con
Ways to use you could find in nice platofrm independed lib - boost::asio
If you are looking to use this as a learning experience I would also look at ACE. A C++ cross platform framework that implements a lot of the patterns discussed in Patterns for Concurrent Network and Networked Objects. The author has also written on ACE as well (see here).