Documentation for pulsar 0.9.2. For development docs, go here.
This example illustrates how to write a UDP Echo server and client pair.
The code for this example is located in the examples.echoudp.manage
module.
To run the server:
python manage.py
Open a new shell, in this directory, launch python and type:
>>> from manage import Echo
>>> echo = Echo(('localhost',8060))
>>> echo(b'Hello!')
b'Hello!'
The first step is to write a small class handling a connection
pool with the remote server. The Echo
class does just that,
it subclass the handy AbstractUdpClient
and uses
the asynchronous Pool
of connections as backbone.
The second step is the implementation of the EchoUdpProtocol
,
a subclass of DatagramProtocol
.
The EchoUdpProtocol
is needed for two reasons:
datagram_received()
method.examples.echoudp.manage.
EchoUdpProtocol
(loop=None, session=1, producer=None, **kw)[source]¶A base DatagramProtocol
for UDP echo clients and servers.
The only difference between client and server is the implementation
of the response()
method.
separator
= '\r\n\r\n'¶A separator for messages.
buffer
= None¶The buffer for long messages
examples.echoudp.manage.
Echo
(address, pool_size=5, loop=None)[source]¶A client for the echo server.
Parameters: |
---|
_loop
¶The event loop used by the client IO requests.
The event loop is stored at this attribute so that asynchronous
method decorators such as task()
can be used.
address
¶remote server UDP address.
examples.echoudp.manage.
server
(name=None, description=None, **kwargs)[source]¶Create the UdpSocketServer
.