Web Development – How to Interface C++ with the Web

cweb-applicationsweb-development

Google is well known for the ridiculous amount of C++ they've coded over the years. Correct me if I'm wrong, but a large part of Google's core search engine is written in C++, isn't it? How does one take a program written in C++ and interface it with a website?

Note: I'm not looking for how Google in particular does this, just how it might be done in general.

Best Answer

Any web software will only send and receive messages through sockets, that's all. You could use any language to do this, it's not specific to languages.

However, you'd better not reinvent the wheel for this kind of work so most languages that are used to do web applications have their set of framework that does the basic communication for you, to allow you to concentrate on the specificities of your project. Ruby have ROR, Python have Django and others, Java as ...etc.

C++ historically didn't have any similar framework until recently:

  • a modern-C++ way of doing it is to use something like CPPCMS;
  • there is also an effort to setup a standard library for web dev. in C++, one of them being cpp-netlib;
  • Recently there have been a release of a cross-platform REST API library for C++11 from Microsoft called Casablanca which also helps;

Now, the "ridiculous amount of C++" that Google is built over is necessary because you need to have very-high-performance modules to solve the kind of problems Google solves. Good luck trying to do the same without any module written in a language focused on performance. I recommend reading the CPPCMS wiki about this subject to understand better. For historic facts, Amazon, Google, Facebook (see Hip Hop and recent Alexandrescu interviews) and some other really big web services do have cores in C++, for obvious computational reasons that are more important than the time lost on programmer productivity.

CPPCMS and cpp-netlib being open source, you can study them if you want to know how to make an application work as a web service using C++. That said, any application that can listen to ports and send data to port can potentially do this, it's all about protocoles (TCP/IP, HTTP, etc.), not code.

Related Topic