[Twisted-Python] UDP some Q's

glyph at divmod.com glyph at divmod.com
Thu May 3 05:16:36 EDT 2007


On 08:42 am, sven-erik.tiberg at ltu.se wrote:
>Don't know how to access objects from the main module in the classes in
>the lib module.
>The tricky part as I see it are ( part of from transive_UDP.py ):
># ------------------------------------------------------------------
>def datagramRecived(self, data):
>        count = 0
>        data_str = string.split(data)
>        for recive_items in data_str:
>            __main__.recived_data[ count ] = float( recive_items )
>            count = count +1
>        __main__.update_on_recive()
>
>#-----------------------------------------------------------------
>The problems are that I need to update __main__.recive.dada before
>calling __main__.updat_on_recive().

There is no Twisted API or special technique that you need to use.  Just 
create your objects with references to all the objects they need to 
manipulate.

For example, in main.py, instead of:

    reactor.listenUDP(self.port, transive_udp('...',2345, 0.05 ))

just do:

    reactor.listenUDP(self.port, transive_udp('...', 2345, 0.05, 
recive_data))

and then add an argument to transive_udp's constructor to refer to the 
data.
>Second how to access the  .send_UDP from the __main__ module.

Similarly, you can keep a reference to transive_udp object in the main 
module.

I might be able to comment more except the attached example is full of 
errors and will not even import.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20070503/33de1faa/attachment.htm 


More information about the Twisted-Python mailing list