C++ server based applications

I have just finished a C++ training course. I am not new to programming; however, C++ has taken me to a new height in what I understand about the broad subject of programming. Here is what I would like to understand. A server (like mine at AWS) is a computer online. How would I create a C++ application on that server and then create a web interface to communicate with that application? I realize my question is broad. I would like someone to point me in the correct direction to understand how this done. I know that someone would ask the valid question “what is my goal?”. For now, I am just trying to understand how C++ is used on a Linux based server (but on the web). I think my goal is to explore all of what is possible with C++ and computers in the cloud. I guess I could/should be asking the questions; is there something I should understand first before asking this? How is C++ accessed via the web? Any information is welcome links, ideas, etc. Thanks
How is C++ accessed via the web?
Probably what you mean is, "How are web services served using C++?"

One way to think of this is, the internet was developed using C/Unix, and webservices are a subset of internet services, mainly services use HTTP. So your webservices server must talk HTTP (irrespective of language).

is there something I should understand first before asking this?
No. But it would help if you understood something about network programming in general, and details of HTTP.

There's an example of a C++ HTTP server here. https://www.boost.org/doc/libs/1_63_0/doc/html/boost_asio/examples.html#boost_asio.examples.cpp03_examples.http_server_3
I think you're free to amend.
Thanks @kbw that answer is extremely helpful. I will research it the way you word it and explain it. :)
closed account (SECMoG1T)
yea you can also use the simpler websocket protocol https://tools.ietf.org/html/rfc6455 instead of http ,there is a c++ library for that websocket++ and you could use it in combination with boost::asio or the standalone asio library , both library are quite simple just afew days and you will be comfortable with them, there are also tutorials on the web

you can use this for server/client based apps such as:
-chat apps
-online games
...numerous possibilities.
Last edited on
Incidentally, as far as I can tell, there are no good websocket libraries for C++.

The only one I can find that supports wss is libwebsocket, and it's really difficult to use.

websocketpp does not support encrypted communication, even though the interface is quite nice. In fact, that's common theme with encryption libraries, the ones with the nice interfaces don't work.
closed account (SECMoG1T)
ooh yea bwt i think you can use policy configuration from boost::Asio boost::asio::ssl::context to set up secure TLS end-point in websocket++ using a callback.

i think you can create a portable secure server/client.

check this examples

server impl:
https://github.com/zaphoyd/websocketpp/blob/0.6.0-permessage-deflate/examples/echo_server_tls/echo_server_tls.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
///copied
websocketpp::lib::shared_ptr<boost::asio::ssl::context> on_tls_init(
    websocketpp::connection_hdl
)
{
  auto ctx = websocketpp::lib::make_shared<boost::asio::ssl::context>(
      boost::asio::ssl::context::sslv23);
  // ... configure ctx as desired
  return ctx;
}

int main()
{
  using websocketpp::lib::placeholders::_1;
  using websocketpp::lib::bind;

  // Create server with Asio TLS configuration.
  websocketpp::server<websocketpp::config::asio_tls> server;
  server.init_asio();

  // Set the handler which will return the `ssl::context`.
  server.set_tls_init_handler(bind(&on_tls_init, _1));

  // set other handlers, listen, accept, run, etc...
}


client with wss support:
https://github.com/zaphoyd/websocketpp/blob/c5b5492e5ce16bd7ab2ae5f37ef432d12437aa98/examples/debug_client/debug_client.cpp

Last edited on
Thank you @Yolanda also... I as I learn more I will look at your examples. :)
@kbw the examples in your answer are extremely helpful to see. I don't fully understand or know how to use them, but they give me a good place to start looking at things. Super!
There's now Boost.Beast:
See, for instance, the examples on this page:

https://www.boost.org/doc/libs/1_67_0/libs/beast/doc/html/beast/examples.html
Topic archived. No new replies allowed.