I have used the Twisted Protocol and ServerFactory interfaces to deal with
situations where I wanted to be listening for incoming connections/packets
in the background while the controller continues running. Below is a code
snippet that illustrates this design pattern. The controller calls
start_entity_listener to begin listening for new connections. When data
arrives on a connection, the dataReceived method in EntityProtocol is
called.
Aaron
--------------------
from twisted.internet.protocol import Protocol, ServerFactory
def start_entity_listener(component):
factory = EntityFactory(component)
from twisted.internet import reactor
port = reactor.listenTCP(6000, factory)
#end start_entity_listener
class EntityProtocol(Protocol):
def dataReceived(self, newdata):
// Process new data
// Optionally, post an event to the controller
#end dataReceived
#end EntityProtocol
class EntityFactory(ServerFactory):
protocol = EntityProtocol
def buildProtocol(self, address):
proto = ServerFactory.buildProtocol(self, address)
return proto
#end buildProtocol
#end EntityFactory
--------------------
On Mon, Apr 25, 2011 at 9:05 PM, Bill Liao <[email protected]> wrote:
> Hi, all,
> It seems we can use twisted for building network apps on top of NOX.
> Nox has a built-in oxidereactor, which I assume is acting as the standard
> reactor for loop. But, I cann't manage to find where the reactor is
> commanded to begin the loop. Normally, we need a reactor and run
> reactor.run() to begin the loop, right?
> And what if I want to build some netapps for receiving files from
> client, what do i need to achieve this using twisted? Just
> reactor.listenUDP?
> I'm confused by the way python runtime is working in NOX. There is only
> one runtime on only one thread? What if I build some blocking mechanic(such
> as udp), will the whole runtime stop and wait? How can I workaround this?
> Many thanks.
> regards
> wliao
> *If the dream is BIG enough,the facts don't count!*
>
> _______________________________________________
> nox-dev mailing list
> [email protected]
> http://noxrepo.org/mailman/listinfo/nox-dev
>
>
_______________________________________________
nox-dev mailing list
[email protected]
http://noxrepo.org/mailman/listinfo/nox-dev