August'24: Kamaelia is in maintenance mode and will recieve periodic updates, about twice a year, primarily targeted around Python 3 and ecosystem compatibility. PRs are always welcome. Latest Release: 1.14.32 (2024/3/24)
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
#!/usr/bin/python
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
= "/usr/share/wesnoth/music/wesnoth-1.ogg"
file_to_stream
class detuple(component):
def __init__(self, index):
super(detuple, self).__init__()
self.index = index
def main(self):
while 1:
if self.dataReady("inbox"):
tuple=self.recv("inbox")
self.send(tuple[self.index], "outbox")
yield 1
class blockise(component):
def main(self):
= 1000 # Needs to be parameterisable
maxlen buffer = ""
while 1:
if self.dataReady("inbox"):
buffer = buffer + self.recv("inbox")
if len(buffer) > maxlen:
= buffer[:maxlen]
send buffer = buffer[maxlen:]
else:
= buffer
send buffer = ""
self.send(send, "outbox")
yield 1
#
# Server with simple added reliabilty protocol
#
pipeline(="bitrate", bitrate=400000, chunkrate=50),
ReadFileAdaptor(file_to_stream, readmode
SRM_Sender(),# Ensure chunks small enough for multicasting!
blockise(), "0.0.0.0", 0, "224.168.2.9", 1600),
Multicast_transceiver(
).activate()
#
# Client with simple added reliability protocol
#
pipeline("0.0.0.0", 1600, "224.168.2.9", 0),
Multicast_transceiver(1),
detuple(
SRM_Receiver(),1),
detuple(
VorbisDecode(),
AOAudioPlaybackAdaptor(), ).run()
Source: Examples/example4/MulticastStreamingSystem_SRM.py