August 22, 2010

Netboa

I've started the total re-write of my asynchronous network library Miniboa. The new code, in addition to being cleaner, is different in several ways.

What's New
  • No longer Telnet-centric; my aim is to keep connections generic and wrap them in protocol handlers.
  • Services; you can now run multiple services under a single server. Each service listens on a different port and can have unique protocols and events.
  • Added hooks for coroutine-based, character-at-a-time protocol handlers.
  • No longer line-based; the new API has get_ch() to get one character or get_input() to retrieve the entire input buffer. This is support users that want to write features like text editors and command completion.
  • New event; on_input() that is called when the data is received from the client.
  • When run under Linux, it uses the Epoll API introduced in Linux kernel 2.5.44. All other platforms user Select().
I kept the server polled from within the user's game loop. I know that event and callback driven designs are more efficient, but I really like the approachability of that pattern. It can be hard to think in terms of callbacks.

4 comments:

Richard said...

The problem with select, is that on Windows it is limited to passing in 512 file descriptors at a time I believe. So if you are going to use it, then you're probably going to want to call it multiple times with batches if you are over this limit -- at least on Windows.

Richard said...

Forgot to tick the box which gets me follow up comments, which must be a nice new addition from blogger. So this comment is me doing that :-)

Jim said...

Yeah, we had a discussion about that a while back on MudBytes. Currently, I hackishly cap to 512 on Windows but according to this post by the asyncore maintainer, 'paging' the sockets should work:

http://bugs.python.org/issue1685000

I think I'll aim for 1,000 sockets across all platforms, which means a max of two sweeps per poll on Windows.

Zita said...

I really feel very interesting to read your articles... You have blog posts on protocols. I love to visit your blogs often.. Thanks for sharing it with us. Ecommerce website developers