Junior — Middle
Do you have experience working with web technologies or web servers?
sobes.tech AI
Answer from AI
Yes, experience with web technologies and web servers in C/C++ includes creating HTTP servers, handling requests, and working with network sockets. For example, libraries like libmicrohttpd or Boost.Asio can be used to implement a simple web server.
Example of a simple HTTP server in C++ using Boost.Asio:
#include <boost/asio.hpp>
#include <iostream>
using boost::asio::ip::tcp;
int main() {
try {
boost::asio::io_context io_context;
tcp::acceptor acceptor(io_context, tcp::endpoint(tcp::v4(), 8080));
for (;;) {
tcp::socket socket(io_context);
acceptor.accept(socket);
std::string response =
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/plain\r\n"
"Content-Length: 13\r\n"
"\r\n"
"Hello, world!";
boost::asio::write(socket, boost::asio::buffer(response));
}
} catch (std::exception& e) {
std::cerr << "Exception: " << e.what() << "\n";
}
return 0;
}
This code demonstrates basic socket handling and processing of HTTP requests at a low level.