#action Blog 블로그 ë”하기 ##Blog {{{#!blog hyacinth 2014-07-13T14:55:01 ì˜¤ëŠ˜ì˜ ìˆ˜í™•(스í¬ëž©) ì‹ ë¬¸ì„ ë³´ë©´ í•˜ë£¨ì— í•œ ë‘ ê°œ ê¼ì§€ ì¸ìƒì ì¸ ê¸€ì´ ìžˆë‹¤. 그래서 몇 ë…„ ì „ì—는 가위로 잘ë¼ì„œ 스í¬ëž©í•˜ê¸°ë„ 했는ë°, ì§€ê¸ˆì€ ìŠ¤ë§ˆíŠ¸í°ìœ¼ë¡œ ì‚¬ì§„ì„ ì°ìœ¼ë©´ 아주 ì •ë¦¬í•˜ê¸° 편하다. 다ìŒì€ ì–´ì œ(7ì›” 12ì¼ í† ìš”ì¼) ìž ì‹ ë¬¸ê³¼ 몇몇 잡지를 ë³´ë©° ì–»ì€ ìˆ˜í™•ë¬¼ì´ë‹¤. 1. '30ë…„ ì•ˆì— ì—†ì–´ì§ˆ ì§ì—…' https://lh6.googleusercontent.com/-a8iYmCJX2L8/U8Jw0hnw9VI/AAAAAAAAEuA/7NrCmZc8dsU/w1313-h985-no/20140713_172132.jpg 지난 3ì›” 17ì¼ LA타임스는 지진 ê´€ë ¨ 소ì‹ì„ ì „í•˜ëŠ” ì†ë³´ 기사를 온ë¼ì¸ì— 냈다. (중략) ë¡œë´‡ì´ ì“´ ì†ë³´ ê¸°ì‚¬ì— BBC 등 ì „ 세계 ì–¸ë¡ ì€ ë¯¼ê°í•˜ê²Œ ë°˜ì‘했다. 2. ì½”ì„¸ë¼ https://lh4.googleusercontent.com/-wL6m4N65AeY/U8JwwXNmMyI/AAAAAAAAEvY/1pNFnCwbjHI/w739-h985-no/20140713_170344.jpg 3. "지금 왜 ì´ê±¸ í•˜ê³ ìžˆì§€" … ë§¤ì¼ ìŠ¤ìŠ¤ë¡œ 질문 ë˜ì ¸ë¼ https://lh6.googleusercontent.com/-4d6NMuhUs4Y/U8Jw9lsObiI/AAAAAAAAEuY/DOaAsCJR-Vg/w1313-h985-no/20140713_181248.jpg 4. 사설 https://lh3.googleusercontent.com/-0ug4Fz6czXo/U8JxK27e8BI/AAAAAAAAEu8/zH-uv15XYRI/w1313-h985-no/20140713_182115.jpg }}} [[HTML(<center>)]] http://hyacinth.byus.net/img/flower.jpg [[HTML(</center>)]] {{{#!blog hyacinth 2014-07-04T05:43:25 경량 C++ 웹 서버 소개 civetweb {{{+1 ê¸€ì˜ ëª©ì \}}} 최근 C/C++ë¡œ êµ¬í˜„ëœ ê°„ë‹¨í•œ 웹 서버를 찾게 ë˜ì—ˆëŠ”ë° ì ì ˆí•œ 프로ì 트를 찾아서 소개한다. {{{+1 소개 \}}} GitHub:bel2125/civetweb Civetweb. C/C++ë¡œ êµ¬í˜„ëœ ì›¹ 서버. 프로ì 트 ì €ìžëŠ” ìž„ë² ë””ë“œ C++ 웹 서버ë¼ê³ í‘œí˜„í•˜ê³ ìžˆë‹¤. 사용하기 ì‰½ê³ ê°•ë ¥í•˜ë‹¤. HTTP와 CGI, SSL, SSI, Lua ë“±ì„ ì§€ì›í•œë‹¤. Civetwebì€ MIT ë¼ì´ì„ 스로 ìƒìš© ì†Œí”„íŠ¸ì›¨ì–´ë„ ì œí•œì—†ì´ ì‚¬ìš©í• ìˆ˜ 있다. Civetwebì€ Cë¡œ êµ¬í˜„ëœ ì›¹ 서버 mongoose 프로ì 트([https://code.google.com/p/mongoose/])ì—ì„œ 분리ë˜ì—ˆë‹¤. mongoose는 ì´ì „까지 MIT ë¼ì´ì„ 스였으나 2013ë…„ 8ì›” GNU GPL v2 ë¼ì´ì„ 스로 변경ë˜ì—ˆë‹¤. 즉, Civetwebì€ mongooseê°€ GPL v2 ë¼ì´ì„ 스를 가지게 ë¨ì— ë”°ë¼ mongooseê°€ ì•„ì§ MIT ë¼ì´ì„ ìŠ¤ì¼ ë•Œ 분리ë˜ì–´ MIT ë¼ì´ì„ 스를 ìœ ì§€í•˜ëŠ” ê²ƒì´ Civetwebì´ ëª…ì‹œí•˜ê³ ìžˆëŠ” 프로ì íŠ¸ì˜ ê°€ìž¥ í° ëª©ì ì´ë‹¤. (프로ì íŠ¸ì— ê¸°ì—¬í•˜ëŠ” 개발ìžë“¤ì—ê²Œë„ GPL ë¼ì´ì„ 스 변경 ì´í›„ mongoose 코드를 사용하지 ë§ ê²ƒì„ ê°•ì¡°í•˜ê³ ìžˆë‹¤. ìµœì‹ ê¸°ëŠ¥ê³¼ Sergey Lyubka(mongooseì˜ ì €ìž)ê°€ 작성한 훌ë¥í•œ ê¸°ëŠ¥ë“¤ì„ ì‚¬ìš©í•˜ê³ ì‹¶ìœ¼ë©´ mongoose를 사용해 달ë¼ê³ ë§í•˜ê³ 있다. ë¬¼ë¡ GNU v2 ë¼ì´ì„ 스를 ìœ ì§€í• ìˆ˜ 있다면.) ë”°ë¼ì„œ GPL ë¼ì´ì„ 스 ì œì•½ì—ì„œ ìžìœ ë¡ê³ 싶으면 mongoose ëŒ€ì‹ Civetwebì€ ê°•ë ¥í•œ ëŒ€ì•ˆì´ ë 것ì´ë‹¤. 최종 사용ìžë¥¼ 위한 서버 í”„ë¡œê·¸ëž¨ì€ SourceForgeì—ì„œ 다운로드 ë°›ì„ ìˆ˜ 있다. https://sourceforge.net/projects/civetweb/ 개발ìžë¥¼ 위한 í’€ 소스 ì ‘ê·¼ì´ë‚˜ 기여는 GitHubì—ì„œ í• ìˆ˜ 있다. https://github.com/bel2125/civetweb í† ë¡ ì€ êµ¬ê¸€ ê·¸ë£¹ì— ì—´ë ¤ìžˆë‹¤. https://groups.google.com/d/forum/civetweb {{{+1 Quick Start }}} 다ìŒì€ ê°œë°œìž ìž…ìž¥ì—ì„œ 얼마나 사용하기 간편한지 보여주는 ì˜ˆì œë‹¤. C 프로ì 트ì—ì„œ Civetwebì„ ì‚¬ìš©í•˜ì—¬ HTTP 서버를 ì—´ì–´ Hello civetwebì„ ë¦¬í„´í•˜ëŠ” ì˜ˆì œë‹¤. GitHub:bel2125/civetweb/tree/master/examples/hello {{{#!gcode #include <stdio.h> #include <string.h> #include "civetweb.h" // This function will be called by civetweb on every new request. static int begin_request_handler(struct mg_connection *conn) { const struct mg_request_info *request_info = mg_get_request_info(conn); char content[100]; // Prepare the message we're going to send int content_length = snprintf(content, sizeof(content), "Hello from civetweb! Remote port: %d", request_info->remote_port); // Send HTTP reply to the client mg_printf(conn, "HTTP/1.1 200 OK\r\n" "Content-Type: text/plain\r\n" "Content-Length: %d\r\n" // Always set Content-Length "\r\n" "%s", content_length, content); // Returning non-zero tells civetweb that our function has replied to // the client, and civetweb should not send client any more data. return 1; } int main(void) { struct mg_context *ctx; struct mg_callbacks callbacks; // List of options. Last element must be NULL. const char *options[] = {"listening_ports", "8080", NULL}; // Prepare callbacks structure. We have only one callback, the rest are NULL. memset(&callbacks, 0, sizeof(callbacks)); callbacks.begin_request = begin_request_handler; // Start the web server. ctx = mg_start(&callbacks, NULL, options); // Wait until user hits "enter". Server is running in separate thread. // Navigating to http://localhost:8080 will invoke begin_request_handler(). getchar(); // Stop the server. mg_stop(ctx); return 0; } \}}} C 코드는 mongooseê³¼ ê±°ì˜ ê°™ë‹¤. C++ í´ëž˜ìŠ¤ë¡œ ëž©í•‘ëœ ë²„ì „ë„ ìžˆë‹¤. {{{ CivetSevrer.cpp civetweb.c Civetserver.h civetweb.h \}}} MFCì—ì„œ ì‚¬ìš©í•˜ë ¤ë©´ ê° í—¤ë”ì— stdafx.h를 ì¶”ê°€í•˜ê³ civetweb.c 확장ìžë¥¼ .cppë¡œ ë³€ê²½í•˜ê³ ì‚¬ì†Œí•œ ìºìŠ¤íŒ… 오류가 나는 몇 ë¶€ë¶„ì„ ìˆ˜ì •í•˜ë©´ ëœë‹¤. CivetServer í´ëž˜ìŠ¤ëŠ” ë‹¤ìŒ ê°™ì´ ì‚¬ìš©í•œë‹¤. 핸들러 í´ëž˜ìŠ¤ë¥¼ ë§Œë“¤ê³ CivetServer í´ëž˜ìŠ¤ë¥¼ ì„ ì–¸í•´ 핸들러를 등ë¡í•˜ë©´ ë난다. GitHub:bel2125/civetweb/tree/master/examples/embedded_cpp/embedded_cpp.cpp CGI, Lua, WebSocket ë“±ë„ ì˜ˆì œë¥¼ ë³´ë©´ ì–´ë µì§€ 않다. Have fun! }}} [[HTML(<center>)]] http://hyacinth.byus.net/img/flower.jpg [[HTML(</center>)]]