[Twisted-Python] Migrate Asyncore to Twisted

jian wu hellojianwu at gmail.com
Wed Mar 14 03:26:23 EDT 2007


Hi Sean,

> I am actually not sure if it is my protocol that is complicated
> or if the way in which I want to pass the data that is complicated.

I should claim that I'm not very well experienced with either Twisted
or asyncore, My guess is that is not protocol but the way to pass
data.

Assuming that your python program is connected to your two
devices with two independent TCP connections, your python
program actually is doing message based routing among two
async bi-directional tcp channels.

My guess is that you can keep two Queues since it will help
keeping the order of the async messages received and processed.
And, since twisted has a thread pool, it might be doable that
you could create four threads, two for each TCP Connections,
one thread for read and another for write per TCP connection,
the read thread will handle the received message, process it
and put it into the Queue, the write thread will take the message
from the Queue and write it out to the targeted TCP connection.

Hope this info might be helpful and Good Luck!

Jian


On 3/13/07, Sean Roark <srock258 at gmail.com> wrote:
> Thanks Jian. I am actually not sure if it is my protocol that is complicated
> or if the way in which I want to pass the data that is complicated. This is
> what I'm doing.
>
> I have two devices that both send and recieve binary strings. Each device
> formats the binary messages in a completely different manner, but
> abstractly, they basicly contain the same information just in different
> formats. I need to recieve the data, parse it, translate it, then repack it
> into this different raw format and send it to another destination. All this
> works just fine using asyncore dispatchers but I have created my own way of
> passing the messages between the different modules. Each module I have
> (parse, translate, pack, recieve, send) is wrapped by two Queue's, one
> taking input and the other taking output. I connect the modules by replacing
> one instance's output Queue with another's input Queue. This way each module
> is a thread that simply blocks on the input Queue. When the Parse instance
> finishes parsing data it puts it on the output Queue which is actually the
> Translate modules input Queue. Since everything needs to happen in a nice
> linear manner this works great.
>
> But, this means I am not using callbacks or anything. Instead I would need
> to wrap the Twisted protocol in my Queue protocol. This seems straight
> forward enough, but I don't have much time to make this conversion (charge
> number is running out!) which is why I would love to see an example of the
> asyncore dispatcher to twisted protocol conversion. It would go along way to
> helping me quickly map my existing code to twisted style code.
>
> My reason's for switching to Twisted are for the future. This may need a web
> interface for configuration and monitoring in the near future. Also,
> asyncore has a myriad of issues on Win32 but we want the program to work on
> both *nix and windows, I'm hoping Twisted helps. Furthermore, the Twisted
> libraries for making my system an application look very appealing as a means
> to ease deployment.
>
> Thanks,
>
> Sean
>
>
> On 3/13/07, jian wu <hellojianwu at gmail.com> wrote:
> > Hi Sean,
> >
> > I had some experience to write a simple python test simulator for my
> > java network
> > application using Apache Mina for a text line based protocol
> >
> > At first I used asyncore.async_chat, then I moved to
> > twisted.protocols.basic.LineReceiver
> > since I need async multi-thread behavior. For me, it is
> > straight-forward regarding handling the protocol when moving from
> > async_chat to LineReceiver.
> >
> > And, asyncore.disptacher is just replaced with Twisted reactor and
> > Factory or TCPServer
> > if you want to write a Twisted Application.
> >
> > If you have a very complicated protocol, it might be totally different
> > from my experience.
> >
> > Best regards,
> >
> > Jian
> >
> >
> > On 3/12/07, Sean Roark <srock258 at gmail.com> wrote:
> > > I would love to migrate my asyncore based applications to Twisted but
> the
> > > learning curve seems quite steep. Anybody have a good tutorial?
> Migrating
> > > asyncore.dispatcher objects to twisted protocols examples would be
> awesome.
> > >
> > > --
> > >
> > > Sean Roark
> > > _______________________________________________
> > > Twisted-Python mailing list
> > > Twisted-Python at twistedmatrix.com
> > >
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
> > >
> > >
> >
> > _______________________________________________
> > Twisted-Python mailing list
> > Twisted-Python at twistedmatrix.com
> >
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
> >
>
>
>
> --
>
> Sean Roark
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>




More information about the Twisted-Python mailing list