Cookbook Example

How can I...?

Example 4: Building some reliability into the system (Simple Reliable Multicast). Idea is to show layering of protocols. Components used: component, ReadFileAdaptor, VorbisDecode, AOAudioPlaybackAdaptor, Multicast_transceiver, pipeline, SRM_Sender, SRM_Receiver


    from Axon.Component import component
    from Kamaelia.ReadFileAdaptor import ReadFileAdaptor
    from Kamaelia.vorbisDecodeComponent import VorbisDecode, AOAudioPlaybackAdaptor
    from Kamaelia.Internet.Multicast_transceiver import Multicast_transceiver
    from Kamaelia.Util.PipelineComponent import pipeline
    from Kamaelia.Protocol.SimpleReliableMulticast import SRM_Sender, SRM_Receiver

    file_to_stream = "/usr/share/wesnoth/music/wesnoth-1.ogg"

    class detuple(component):
    def __init__(self, index):
    super(detuple, self).__init__()
    self.index = index
    def main(self):
    while 1:
    if self.dataReady("inbox"):
    self.send(tuple[self.index], "outbox")
    yield 1

    class blockise(component):
    def main(self):
    maxlen = 1000 # Needs to be parameterisable
    buffer = ""
    while 1:
    if self.dataReady("inbox"):
    buffer = buffer + self.recv("inbox")
    if len(buffer) > maxlen:
    send = buffer[:maxlen]
    buffer = buffer[maxlen:]
    send = buffer
    buffer = ""
    self.send(send, "outbox")
    yield 1

    # Server with simple added reliabilty protocol
    ReadFileAdaptor(file_to_stream, readmode="bitrate", bitrate=400000, chunkrate=50),
    blockise(), # Ensure chunks small enough for multicasting!
    Multicast_transceiver("", 0, "", 1600),

    # Client with simple added reliability protocol
    Multicast_transceiver("", 1600, "", 0),

    Source: Examples/example4/


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

This web site is powered by the same code created for the bicker manor project. For more details, contact Michael Sparks at BBC Research directly (cf contact)