[Boost] ASIO學習筆記:hello_world
ASIO為Boost中的一套網路函式庫,全名為asynchronous input/output,如同他的名稱,這個函式庫的核心是在處理各種同步或非同步的問題。 要學習這套函式庫,其實最好是先從其官方的教學開始:http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio.html 其實寫的還蠻不錯的,再來就是可以搭配以下幾個教學:http://www.gamedev.net/blog/950/entry-2249317-a-guide-to-getting-started-with-boostasio?pg=2http://en.highscore.de/cpp/boost/index.html 以下為一個最簡單的asio程序: #include <boost/asio.hpp> #include <iostream> int main( int argc, char * argv[] ){ boost::asio::io_service io_service; io_service.run(); std::cout < < “Hello world!” << std::endl; return 0; } 以上程序還沒有關係到網路,主要就只是在展示我們的程式跟OS系統操作權之間的轉移而已 其中io_service為我們的程式跟operating system’s I/O services的接口而io_service.run()會將系統操作權交給OS,而我們的程式會一直block在這一行,直至所有非同步的工作已經完成 關於非同步,讓我們來看加入非同步操作情形來解釋: #include <boost/asio.hpp> #include <iostream> … Continued