[ Curiosity,Experimentation ]

Random stuff from the parallel universe of Ones and Zeroes

Archive for November, 2009

An Asynchronous Socket Class in Python

Posted by appusajeev on November 23, 2009

The default socket module can be a pain certain times,especially when you are working with asynchronous/event driven domain.Handling asynchronous communication can be a bit messy in the native python environment .The accept() and recv() methods would only relinquish control after a connection has been accepted or data has arrived. This would sometimes choke the flow of control in the program..
So i thought of creating a socket class utilizing threads internally to handle asynchronous communication and this is what i have finally arrived at.
The Winsock control in VB provides a clean yet powerful interface to handle asynchronous socket communication.I have tried to provide an interface similar to the Winsock control. I have also incorporated callback mechanism by which a function could be invoked upon data arrival.This avoids the need to poll the socket every time. As of now i have just provided the methods working upon TCP,UDP is not yet supported though adding UDP support is trivial ! ๐Ÿ™‚

Download Source

An Asynchronous Socket Class in Python Source

An Asynchronous Socket Class in Python

Posted in Asynchronous_Socket, Python | Tagged: , | 3 Comments »