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 1: Building a Simple TCP Based Server that allows multiple connections at once and sends a fortune cookie to the client. Includes simple TCP based client that displays the fortune cookie. Components used:SimpleServer, FortuneCookieProtocol, Pipeline, TCPClient, ConsoleEchoer
#!/usr/bin/python
from Kamaelia.Protocol.FortuneCookieProtocol import FortuneCookieProtocol
from Kamaelia.SimpleServerComponent import SimpleServer
from Kamaelia.Internet.TCPClient import TCPClient
from Kamaelia.Util.Console import ConsoleEchoer
from Kamaelia.Chassis.Pipeline import Pipeline
import random
=random.randint(1500,1599)
clientServerTestPort
=FortuneCookieProtocol, port=clientServerTestPort).activate ()
SimpleServer(protocol
Pipeline("127.0.0.1",clientServerTestPort),
TCPClient(
ConsoleEchoer() ).run()
Source: Examples/example1/FortuneCookie_ServerClient.py