To make turbogears talk to a data source other than Database

0 views
Skip to first unread message

一首诗

unread,
Dec 12, 2006, 9:55:59 AM12/12/06
to TurboGears
Hi all,

I have to make my turbogears program talk to a remote server by UDP,
which means while handling a http request in controller.py, I have to
send out an UDP package and block the thread until the response is
received.

I have little idea of how to make this happen. Maybe I could write
another thread to send and receive packages, and wake up the waiting
thread correctly.

Do u have any suggestions? Thanks a lot?

By the way, I also need to process the binary data in UDP packages, and
it's a little complicated to use struct. Is there any more convenient
packages that you may recommend?

Thanks again!

Adam Jones

unread,
Dec 12, 2006, 11:09:40 AM12/12/06
to TurboGears

一首诗 wrote:
> Hi all,
>
> I have to make my turbogears program talk to a remote server by UDP,
> which means while handling a http request in controller.py, I have to
> send out an UDP package and block the thread until the response is
> received.
>
> I have little idea of how to make this happen. Maybe I could write
> another thread to send and receive packages, and wake up the waiting
> thread correctly.
>
> Do u have any suggestions? Thanks a lot?

If blocking the thread is acceptable just run the UDP action in-thread.
There are alternatives, but if you don't need to process that
interaction asynchronously set up a separate module and call it
directly from the controller.

If you *do* need the UDP connection and controller method to be
independent (i.e. you have more people using this than you can spawn CP
threads for or the communication takes a long time) I would suggest
setting up a separate "server" (which could run on the same host) and
pass it a unique key that it can use to return the data. (through
POSTing to a specified controller method, for example) At that point
the server doesn't even necessarily have to be written in Python.

>
> By the way, I also need to process the binary data in UDP packages, and
> it's a little complicated to use struct. Is there any more convenient
> packages that you may recommend?
>
> Thanks again!

I'm not terribly experience there, but I have heard good things about
hachior[1] The website says it is for "binary files", but if it isn't
able to read in-memory objects I'm sure someone has found a way to fake
a file enough to make it work.

-Adam

[1] http://hachoir.org/

一首诗

unread,
Dec 12, 2006, 11:33:06 AM12/12/06
to TurboGears
I'm not sure how to make the UDP action in thread because I could use
only one port to received response.

But the idea of using POST method is excellent! Changing UDP action to
TCP action sovled my problem.

Reply all
Reply to author
Forward
0 new messages