Fog Creek Software
Discussion Board




Pointers on event-driven network programming?

I'm implementing the client side of a client/server network protocol that allows for:

*connected (TCP) and connectionless (UDP) sessions (with state maintained using a session ID and sequence numbers);

* pipelining (sending multiple requests one after the other without waiting for the corresponding responses);

* and for the server to send requests to the client (when using a connected session).

These three features require near-simultaneous reading and writing, which means either a multithreaded model or an event-driven model.

I've chosen the event-driven model, since it's more portable (in Perl, which I'm using) and less error prone. Does anyone have any pointers on event-driven network programming? Any opinions/experiences? Recommended books or URLs?

A Drifter Lost in Philadelphia
Sunday, April 18, 2004

If you're using perl, check out POE... http://poe.perl.org/
It is basically a framework for writing event-driven network applications.

Dwilliams
Sunday, April 18, 2004

POE, unfortunately, isn't an option :(

A Drifter Lost in Philadelphia
Sunday, April 18, 2004

Am not familiar with POE, (and it would help to explain _why_ it isn't an option for you .....) - but if you read Python, there's lots of interesting material down at http://twistedmatrix.com

Ori Berger
Sunday, April 18, 2004

Ori previously convinced me to implement a server that I am working on using a single threaded, event driven, model, and I have to say I'm glad I did it.  It takes a slight twist of logic, but in the end I think it is easier than synchronizing a multithreaded server.  It turns out to be a trade off between synchronization problems vs handling a large state machine. 

You probably want to check out Dan Kegel's site as well. http://www.kegel.com/c10k.html.  Dan helped me out a lot as I worked out some of the issues on my C++ server. 

You have to decide on level-triggered vs edge-triggered.  The model for edge-triggering isn't obvious at first, but all it requires is that you create a small struct to save the state of the socket.  Basically on a level triggered server you have to hold the state of being able to read or write. 

Select based mechanisms are level-tiggered, slower and more portable, while sys_epoll is selectable between level and edge triggering.  The sigio stuff in older linux versions is also edge triggered, but it can get pretty wierd when the signal queue overflows.

christopher baus (www.baus.net)
Sunday, April 18, 2004

Check out http://www.eecs.harvard.edu/~mdw/proj/seda/
SEDA is Staged, Event-Driven Architecture.  It's high-level - it won't give you a library to work with or anything, but it may help you model the problem and solution in a way that makes it easier to work with.

schmoe
Monday, April 19, 2004

Thanks for the help guys.

I now know what to do and how to do it.

A Drifter Lost in Philadelphia
Wednesday, April 21, 2004

*  Recent Topics

*  Fog Creek Home