{"id":5598,"date":"2026-05-08T12:04:59","date_gmt":"2026-05-08T03:04:59","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=5598"},"modified":"2026-05-08T12:05:18","modified_gmt":"2026-05-08T03:05:18","slug":"webserve-rminiwebserver-7","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2026\/05\/08\/webserve-rminiwebserver-7\/","title":{"rendered":"[Webserver]miniWebserver-(7)"},"content":{"rendered":"\n<p>\ud83d\udc49\ud83c\udffb \uc8fc\uc694 \ubcc0\uacbd\uc0ac\ud56d\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<br>The major changes are as follows.<\/p>\n\n\n\n<p>\u2714\ufe0f \uba40\ud2f0 \uc11c\ubc84 \/ multi server<\/p>\n\n\n\n<p>&#8212; \ud3ec\ud2b8 \ubc88\ud638\ub97c \ubc14\uafd4\uc11c \uc5ec\ub7ec\uac1c\uc758 \uc11c\ubc84\ub97c \ub3d9\uc2dc\uc5d0 \uc2e4\ud589 \uac00\ub2a5\ud569\ub2c8\ub2e4.<br>You can run multiple servers simultaneously by changing the port number.<\/p>\n\n\n\n<p>&#8212; Main.cpp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Server server1(\"127.0.0.1\", 5080); \nserver1.set_handler(&#91;&amp;](const std::string&amp; req) { ... }\n\nServer server2(\"127.0.0.1\", 6080);\nserver2.set_handler(&#91;&amp;](const std::string&amp; req) { ... }\n\nstd::thread server_thread(&amp;Server::start, &amp;server1);\nstd::thread server_thread2(&amp;Server::start, &amp;server2);\n\nserver1.stop();\nserver2.stop();\n\nif (server_thread.joinable()) {\n   server_thread.join();\n}\nif (server_thread2.joinable()) {\n   server_thread2.join();\n}<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \uc11c\ubc84\ubcc4\ub85c \uc815\uc801\ud30c\uc77c \uc11c\ube59 \ubc0f \ub77c\uc6b0\ud2b8 \uc124\uc815 \uac00\ub2a5\ud569\ub2c8\ub2e4.<br>Static file serving and routing can be configured per server.<\/p>\n\n\n\n<p>&#8212; Main.cpp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    Router server1_router(\"..\/public1\");\n    server1_router.add_route(\"\/test1\", \"test1.html\");\n    server1_router.add_route(\"\/test2\", \"test2.html\");\n\n    Router server2_router(\"..\/public2\");\n    server2_router.add_route(\"\/test1\", \"test1.html\");\n    server2_router.add_route(\"\/test2\", \"test2.html\");<\/code><\/pre>\n\n\n\n<p>&#8212; Router.h<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public:\n    void add_route(const std::string&amp; path, const std::string&amp; file_name) {\n        route_map&#91;path] = file_name;\n    }\n\nprivate:\n    std::map&lt;std::string, std::string&gt; route_map;<\/code><\/pre>\n\n\n\n<p>&#8212; Router.cpp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    std::string target_file;\n\n    \/\/ 1. \ub4f1\ub85d\ub41c \ub77c\uc6b0\ud2b8\uac00 \uc788\ub294\uc9c0 \ud655\uc778\n    \/\/ Check if there are registered routes\n    if (route_map.count(path)) {\n        target_file = route_map&#91;path];\n    }\n    \/\/ 2. \uae30\ubcf8 \uacbd\ub85c(\"\/\") \ucc98\ub9ac\n    \/\/ Handling default path (\"\/\")\n    else if (path == \"\/\") {\n        target_file = \"index.html\";\n    }\n    \/\/ 3. \ub4f1\ub85d\ub418\uc9c0 \uc54a\uc740 \uacbd\ub85c\ub294 \uadf8\ub0e5 \uacbd\ub85c \uc774\ub984\ub300\ub85c \ud30c\uc77c \uc2dc\ub3c4 (\ub610\ub294 404)\n    \/\/ For unregistered paths, just attempt the file as the path name (or 404)\n    else {\n        target_file = path;\n    }\n\n    std::string full_path = doc_root + \"\/\" + target_file;<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f Servre listening \uba54\uc138\uc9c0 \uc774\ud6c4 CMD&gt; \ucd9c\ub825\ud558\ub3c4\ub85d \uc218\uc815\ud588\uc2b5\ub2c8\ub2e4.<br>Modified to output CMD&gt; after the Servre listening message.<\/p>\n\n\n\n<p>&#8212; Main.cpp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>std::this_thread::sleep_for(std::chrono::milliseconds(200));<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \ub514\ubc84\uae45\uc6a9 \uba54\uc138\uc9c0\ub294 \ucf54\uba58\ud2b8 \ucc98\ub9ac \ub410\uc2b5\ub2c8\ub2e4.<br>Debugging messages have been commented out.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb\ube4c\ub4dc \/ Build<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd build\ncmake ..\nmake<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \uc2e4\ud589 \/ Run<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MacBookAir build % .\/main\n--- Starting Server Application ---\nServer listening on port 5080...\nServer listening on port 6080...\nCMD&gt; <\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb\ube0c\ub77c\uc6b0\uc800 \uc811\uc18d \/ Access Browser<\/p>\n\n\n\n<p>&#8212; 5080\uacfc 6080 \ud3ec\ud2b8\ub85c \ub450 \uac1c\uc758 \uc11c\ubc84\uac00 \uc2e4\ud589\ub429\ub2c8\ub2e4.<br>Two servers are running on ports 5080 and 6080.<\/p>\n\n\n\n<p>&#8212; \ube0c\ub77c\uc6b0\uc800\uc5d0\uc11c \uac01 \ud3ec\ud2b8\ub85c \uc811\uc18d\ud558\uba74 \ub429\ub2c8\ub2e4.<br>You can connect to each port in your browser.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;localhost:5080\nhttp:\/\/localhoset:6080<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ud83c\udffb \uc8fc\uc694 \ubcc0\uacbd\uc0ac\ud56d\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.The major changes are as follows. \u2714\ufe0f \uba40\ud2f0 \uc11c\ubc84 \/ multi server &#8212; \ud3ec\ud2b8 \ubc88\ud638\ub97c \ubc14\uafd4\uc11c \uc5ec\ub7ec\uac1c\uc758 \uc11c\ubc84\ub97c \ub3d9\uc2dc\uc5d0 \uc2e4\ud589 \uac00\ub2a5\ud569\ub2c8\ub2e4.You can run multiple servers simultaneously by changing the port number. &#8212; Main.cpp \u2714\ufe0f \uc11c\ubc84\ubcc4\ub85c \uc815\uc801\ud30c\uc77c \uc11c\ube59 \ubc0f \ub77c\uc6b0\ud2b8 \uc124\uc815 \uac00\ub2a5\ud569\ub2c8\ub2e4.Static file serving and routing can be configured per server. &#8212; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,1],"tags":[],"class_list":["post-5598","post","type-post","status-publish","format-standard","hentry","category-cpp","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5598","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=5598"}],"version-history":[{"count":2,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5598\/revisions"}],"predecessor-version":[{"id":5600,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5598\/revisions\/5600"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=5598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=5598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=5598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}