I've been reading Boost Asio
's Tutorials (Official website). But I found them a pain in the neck! Is There a simple tutorial on asio?! I mean, A simple client-server chat. NO THREADS!!
Thank you!
Asked
Active
Viewed 3.5k times
22

Kia.celever
- 635
- 2
- 9
- 16
-
3I've never used boost, but doesn't Asio stand for asyncronous io? Isn't threading "the point"? – Seth Carnegie Oct 28 '11 at 14:30
-
6@Seth the two typical schemes are "asynchronous I/O" vs "threaded synchronous I/O". Often the point of asynchronous I/O is to avoid using one thread per connection, where each thread uses synchronous I/O. You can of course use threads and asynchronous I/O together if you want -- but that complicates things further (which I guess is what the OP is trying to avoid). – wjl Oct 28 '11 at 15:08
-
@Kia at a glance, the boost asio library is a bit complex and opaque, but as far as I could see, the boost asio tutorials do not use any threads. Is this incorrect? – wjl Oct 28 '11 at 15:11
-
5Here are some Asio slides from BoostCon 2010: [Getting Started with Asio](http://dl.dropbox.com/u/10282384/asio_presentation_with_story.pdf) – ildjarn Oct 28 '11 at 16:24
-
@wjl - The [boost chat client example](http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/example/chat/chat_client.cpp) runs its `io_service` routine in a thread. – Robᵩ Oct 28 '11 at 17:16
-
@Seth / others - I think there's some confusion here about the whole async i/o vs threaded synch... They're both the same thing. No call can be asynchronous without being put into its own thread, unless you call fork() directly before the read/write/accept etc. If your referring to non-blocking one has nothing to do with the other. non-blocking calls are not asynchronous unless put into their own thread, and blocking calls are equally asynchronous if threaded. BTW asio calls are all blocking unless you set socket.blocking as false, this includes async_read_some() etc. – JSON Jul 12 '13 at 05:18
-
For what its worth, non-blocking are best when used synchronously as they can exit often leading to many repeated reads/writes per message. This isn't too bad if your using a thread pool, but will cause multiple new threads to be spawned otherwise. In boost asio this means running io_service in multiple threads as it doesn't yet have thread pools for boost::thread – JSON Jul 12 '13 at 05:38
3 Answers
11
http://www.boost.org/doc/html/boost_asio/tutorial/tutdaytime1.html
Is there anything wrong with the above? That's where I learnt to use Boost::Asio when I used it.

ildjarn
- 62,044
- 9
- 127
- 211

blaaaaaaah
- 184
- 1
- 4
-
Although I accept that this is the ones from the official site, it's pretty straight forward. – blaaaaaaah Oct 28 '11 at 14:49
10
It's not a chat tutorial and it uses threads but this tutorial is fairly simple to follow:
http://www.gamedev.net/blog/950/entry-2249317-a-guide-to-getting-started-with-boostasio/

Ivan Santos
- 624
- 1
- 8
- 21
2
This blog seems to be by the/an author of the ASIO library and has lots of extra information about it.
For example: boost::asio vs asio, fork/join with asio.

wjl
- 7,519
- 2
- 32
- 41