Thursday, May 17, 2007

python twisted

It is just over 1 year that I have used twisted. I actually used Perl POE before I used twisted. It does not matter which one is chosen. Python users will use twisted, Perl users will use POE. They both are very useful. Personally, I prefer twisted simply because I am a python user.
These are called asynchronous high level network framework. Sometimes word 'abstracted' is attached in introductory contents.
First thing we have to focus is what it is. 'Abstracted' or 'High level' can be best described as 'Protocol Implemented'. I do not have to worry about protocol specifics. I just call methods from objects instantiated from twisted.SomePackage. And asynchronous means, not synchronous. Then, someone may ask what is synchronous? Let's simplify that 'synchronous' is similar way to have conversation between human beings. One person asks, and wait until the other responses. Peers don't speak at the same time. In asynch mode, they do. More in detail can be found in Unix Network Programming ( a.k.a UNP ). There are more in detail about asynchronous communication (non-blocking, signal driven, etc.) I recommend reading UNP for network programmers. Chapters about Async-communication was the best.
With these network frameworks, any network driven application can be very simplified in terms of number of lines of code. Especially, server applications processing custom protocols are very simplified. Buffer handling/IO handling is almost trivial and the performance is even faster thanks to async IO's better utilization of bandwidth.

This morning, I have written another network server processing message from various servers. The key word is 'This Morning'. That's right. I wrote this in low degree of hours. Actually, in 2 hours. I just process the message and stuff into sqlite3, and my life goes on. If I have to write the same code in C, it should take up at least 1 day. :)

No comments: