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 13: How to build a simple system for sending data from a UDP client to a UDP server. Components used:pipeline, Chargen, ConsoleEchoer, SimplePeer
Simple Kamaelia Example that shows how to use a simple UDP Peer. A UDP Peer actually sends and recieves however, so we could havemore fun example here with the two peers sending each other messages.
It's worth noting that these aren't "connected" peers in any shape or form, and they're fixed who they're sending to, etc, which is why it's a simple peer.
#!/usr/bin/python
from Kamaelia.Util.Console import ConsoleEchoer
from Kamaelia.Util.PipelineComponent import pipeline
from Kamaelia.Util.Chargen import Chargen
from Kamaelia.Internet.UDP import SimplePeer
= "127.0.0.1"
server_addr = 1600
server_port
pipeline(
Chargen(),=server_addr, receiver_port=server_port),
SimplePeer(receiver_addr
).activate()
pipeline(=server_addr, localport=server_port),
SimplePeer(localaddr
ConsoleEchoer() ).run()
Source: Examples/example13/UDP_demo.py