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.Util.PipelineComponent import pipeline
import random
clientServerTestPort=random.randint(1500,1599)
SimpleServer(protocol=FortuneCookieProtocol, port=clientServerTestPort).activate()
pipeline(TCPClient("127.0.0.1",clientServerTestPort),
ConsoleEchoer()
).run()
(C) 2006 Kamaelia Contributors, including the British Broadcasting Corporation, All Rights Reserved, 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.