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 2: A Simple TCP Based Server that allows multiple connections at once, but sends a random ogg vorbis file to the client. Includes a simple TCP based client for this server, that connects to the server, decodes the ogg vorbis audio and plays it back. Components used:pipeline, SimpleServer, ReadFileAdaptor, TCPClient, VorbisDecode, AOAudioPlaybackAdaptor
#!/usr/bin/python
from Kamaelia.Util.PipelineComponent import pipeline
from Kamaelia.SimpleServerComponent import SimpleServer
from Kamaelia.Internet.TCPClient import TCPClient
from Kamaelia.vorbisDecodeComponent import VorbisDecode, AOAudioPlaybackAdaptor
import Kamaelia.ReadFileAdaptor
= "/usr/share/wesnoth/music/wesnoth-1.ogg"
file_to_stream
=1500
clientServerTestPort
def AdHocFileProtocolHandler(filename):
class klass(Kamaelia.ReadFileAdaptor.ReadFileAdaptor):
def __init__(self,*argv,**argd):
super(klass,self).__init__(filename, readmode="bitrate", bitrate=400000)
return klass
=SimpleServer(protocol=AdHocFileProtocolHandler(file_to_stream),
server=clientServerTestPort).activate()
port
pipeline("127.0.0.1",clientServerTestPort),
TCPClient(
VorbisDecode(),
AOAudioPlaybackAdaptor() ).run()
Source: Examples/example2/SimpleStreamingSystem.py