一首诗 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/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~---

