Random musings on random stuff.
On the #kamaelia IRC channel , the issue was raised that a number of the examples on the Kamaelia website are just that, small examples, perhaps too small to be useful beyond illustrating the basic idea. (I'm not sure this is universally true, but I accept its definitely the place in more places than we'd like!). Now, one thing we've got planned for the december release is to include a lot more examples, and as a result I'm interested in hearing what sort of examples people would find useful. For example, the example mentioned on the channel is "what does a simple chat server look like" ? (and hence why I'm interested in what examples people would find interesting/useful)
Well, the reason there wasn't an example of that up is because it's a really trivial example in Kamaelia. The most basic version for example looks like this:
from Kamaelia.Util.Backplane import Backplane, PublishTo, SubscribeToA slightly more interesting version, which at least tells clients who they're talking to, and also has slightly better (more explicit) structure is this:
from Kamaelia.Chassis.ConnectedServer import ServerCore
from Kamaelia.Chassis.Pipeline import Pipeline
Backplane("CHAT").activate() # This handles the sharing of data between clients
def ChatClient(*argv, **argd):
return Pipeline(
PublishTo("CHAT"), # Take data from client and publish to all clients
SubscribeTo("CHAT"), # Take data from other clients and send to our client
)
print "Chat server running on port 1501"
ServerCore(protocol = ChatClient, port=1501).run()
#!/usr/bin/pythonTo try this yourself:
from Kamaelia.Util.Backplane import Backplane, PublishTo, SubscribeTo
from Kamaelia.Chassis.ConnectedServer import ServerCore
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.Util.PureTransformer import PureTransformer
Backplane("CHAT").activate() # This handles the sharing of data between clients
def ChatClient(*argc, **argd):
peer = argd["peer"]
peerport = argd["peerport"]
return Pipeline(
PureTransformer(lambda x: " %s:%s says %s" % (str(peer), str(peerport), str(x))),
PublishTo("CHAT"), # Take data from client and publish to all clients
# ----------------------
SubscribeTo("CHAT"), # Take data from other clients and send to our client
PureTransformer(lambda x: "Chat:"+ str(x).strip()+"\n"),
)
class ChatServer(ServerCore):
protocol = ChatClient
print "Chat server running on port 1501"
ChatServer(port=1501).run()
from Kamaelia.Chassis.Pipeline import PipelineTo run that (assuming you have pygame installed):
from Kamaelia.UI.Pygame.Text import Textbox, TextDisplayer
from Kamaelia.Internet.TCPClient import TCPClient
Pipeline(
Textbox(size = (800, 300), position = (100,380)),
TCPClient("127.0.0.1", 1501),
TextDisplayer(size = (800, 300), position = (100,40))
).run()

Plaxo has a python script for crawling your Open Social Graph. They mention that it's not yet multi-threaded.
-- Sam Hasler
Very cool! I love how simple it looks when parts are put together like this :)
Go pipes!
Thank you for your kind words. It's very much appreciated :-)
Hi Michael,
I am trying to modify thie chat server to promot for a name, then hand control to the Pipeline. I also want it to detect disconnect, since it is a TCP connection.
I am guessing that I first need to set the protocol in the ChatServer to somethign else which will allow reads/writes from and to this client. I then need to take the second request from the client, validate them (make sure they entered a name), and then pass it to Pipeline.
Please don't write this for me. I am using this as one of the examples I'll show at PyCon (My goal is to have several simple examples, and walk through them line by line. I've been quietly putting them together, and this looks like a nifty new one :). Just point me in the correct general direction. Which protocol would I use to get access to this client's inbox and outbox? Can I do anything else inside of ChatServer other than pass it parameters?
Also, why does it take so long for the server port to be released between invocations?
Sadly, this demo may be cancelled, due to not meeting the minimum requirement of ten attendees. But I'll keep preparing these until I hear otherwise. I am enjoying this immensely, regardless of presenting or not.
Thanks again, keep them coming!
Gloria
strangest at comcast dot net