Simple UDP componentsThese components provide simple support for sending and receiving UDP packets. Note that this components are deemed somewhat experimental. Example UsageSend console input to port 1500 of myserver.com and receive packets locally on port 1501 displaying their contents (and where they came from) on the console: from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.Util.Console import ConsoleEchoer from Kamaelia.Util.Console import ConsoleReader from Kamaelia.Internet.UDP import SimplePeer Pipeline( ConsoleReader(), SimplePeer("127.0.0.1", 1501, "myserver.com", 1500), ConsoleEchoer(), ).run() Sends data from a data source as UDP packets, changing between 3 different destinations, once per second: class DestinationSelector(component): def main(self): while 1: for dest in [ ("server1.com",1500), ("server2.com",1500), ("server3.com",1500), ]: self.send(dest,"outbox") next=time.time()+1.0 while time.time() < next: yield 1 Graphline( SOURCE = MyDataSource(), SELECT = DestinationSelector(), UDP = TargettedPeer(), linkages = { ("SOURCE", "outbox") : ("UDP", "inbox"), ("SELECT", "outbox") : ("UDP", "target"), } ).run() Send UDP packets containing "hello" to several different servers, all on port 1500: from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.Util.DataSource import DataSource from Kamaelia.Internet.UDP import PostboxPeer Pipeline( DataSource( [ ("myserver1.com",1500,"hello"), ("myserver2.com",1500,"hello"), ("myserver3.com",1500,"hello"), ] ), PostboxPeer(), ).run() BehaviourWhen any of these components receive a UDP packet on the local address and port they are bound to; they send out a tuple (data,(host,port)) out of their "outbox" outboxes. 'data' is a string containing the payload of the packet. (host,port) is the address of the sender/originator of the packet. SimplePeer is the simplest to use. Any data sent to its "inbox" inbox is sent as a UDP packet to the destination (receiver) specified at initialisation. TargettedPeer behaves identically to SimplePeer; however the destination (receiver) it sends UDP packets to can be changed by sending a new (host,port) tuple to its "target" inbox. PostboxPeer does not have a fixed destination (receiver) to which it sends UDP packets. Send (host,port,data) tuples to its "inbox" inbox to arrange for a UDP packet containing the specified data to be sent to the specified (host,port). None of these components terminate. They ignore any messages sent to their "control" inbox and do not send anything out of their "signal" outbox. Implementation DetailsSimplePeer, TargettedPeer and PostboxPeer are all derived from the base class BasicPeer. BasicPeer provides some basic code for receiving from a socket. Although technically BasicPeer is a component, it is not a usable one as it does not implement a main() method. Kamaelia.Internet.UDP.PostboxPeerclass PostboxPeer(BasicPeer)PostboxPeer([localaddr][,localport]) -> new PostboxPeer component. A simple component for receiving and transmitting UDP packets. It binds to the specified local address and port - from which it will receive packets. Sends packets to individually specified destinations Arguments:
Inboxes
Outboxes
Methods defined hereWarning! You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers. Methods inherited from Kamaelia.Internet.UDP.BasicPeer :
Kamaelia.Internet.UDP.SimplePeerclass SimplePeer(BasicPeer)SimplePeer([localaddr][,localport][,receiver_addr][,receiver_port]) -> new SimplePeer component. A simple component for receiving and transmitting UDP packets. It binds to the specified local address and port - from which it will receive packets and sends packets to a receiver on the specified address and port. Arguments:
Inboxes
Outboxes
Methods defined hereWarning! You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers. Methods inherited from Kamaelia.Internet.UDP.BasicPeer :
Kamaelia.Internet.UDP.TargettedPeerclass TargettedPeer(BasicPeer)TargettedPeer([localaddr][,localport][,receiver_addr][,receiver_port]) -> new TargettedPeer component. A simple component for receiving and transmitting UDP packets. It binds to the specified local address and port - from which it will receive packets and sends packets to a receiver on the specified address and port. Can change where it is sending to by sending the new (addr,port) receiver address to the "target" inbox. Arguments:
Inboxes
Outboxes
Methods defined hereWarning! You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers. Methods inherited from Kamaelia.Internet.UDP.BasicPeer :
FeedbackGot a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording! Please leave you feedback here in reply to the documentation thread in the Kamaelia blog. -- Automatic documentation generator, 05 Jun 2009 at 03:01:38 UTC/GMT |
Kamaelia
is an open source project originated from and guided by BBC
Research. For more information browse the site or get in
contact.
This is an ongoing community based development site. As a result the contents of this page is the opinions of the contributors of the pages involved not the organisations involved. Specificially, this page may contain personal views which are not the views of the BBC. (the site is powered by a wiki engine)
(C) Copyright 2008 Kamaelia Contributors, including the British Broadcasting Corporation, All Rights Reserved.