A simple HTTP server using C++ and Winsock. This is a beginner project intended to learn. Therefore, the coding has a lot of indentation.
This would be a great start to learn how to make an HTTP server that outputs a basic HTTP response along with a HTML page to show on the web browser
This is only for windows as some of the components used are Windows only
-
First the build files have to be generated using cmake. Here MinGW used , MinGW build files are generated using the
-Gflag and specified the build folder using-Bflagcmake -G "MinGW Makefiles" -B .\build\
-
Then the executable have to be built using this:
cmake --build .\build\
.\build
- C++
- WinSock
- CMake
- gcc (for compiling C++)
- Sends a HTTP message with the HTML to show in the browser
- "index.html" is the file for the server to show to the client
- Added a file named "server_extra.cpp" which would hold all the definition for the functions used for aesthetic purpose.
- Here, a thing to be noted that, this extra things can be removed without compromising any functionality
- After Sending the data, the sockets are closed
- The cleanup and closing happens on the deletion of the server object
- Starts Listening to the socket using the listen function
- Creates a Client socket
- Accepts the client socket when went into the url
- Created a port view to view the URL in terminal
- Binded the socket with the address which was picked up using getaddrinfo function
- After binding, the getaddrinfo function is no longer needed.
- The freeaddrinfo function is called to free the memory allocated by the getaddrinfo function for this address information.
- Added Documentation for all this
- Created a wrapper for using getaddrinfo function which provides protocol-independent translation from an ANSI host name to an address.
- Created a socket which the client will listen for connection with fault tolerance
- Added documentation for all this
- Added building process in the Readme.md
- Added a Readme.md describing the building process
- Adding documentation for the code
- Initialised Winsock using the official documentation.
- Here, the Winsock is linked with the main using cmake.
- And, upon initialising or failing it outputs a message showing the status of the initialisation
- Created all the boiler plate for the project including the main file and the Cmake file to build the source.