Socket Servers

Asynchronous application for serving requests on sockets. This is the base class of WSGIServer. All is needed by a SocketServer application is a callable which build a ProtocolConsumer for each new client request received. This is an example of a script for an Echo server:

import pulsar
from pulsar.apps.socket import SocketServer

class EchoServerProtocol(pulsar.ProtocolConsumer):

if __name__ == '__main__':

Check the echo server example for detailed implementation of the EchoServerProtocol class.

Socket Server Settings

All standard application settings can be applied to a SocketServer. In addition, the following are specific to sockets and can be used to fine tune your application:


To specify the address to bind the server to:

python --bind

This will accept connection from the network interface and port 8070. This means pulsar will be able to accept connections only from clients running into the same computer it is running.

On the other hand, it is possible to listen for connections from all the network interfaces available on the server by specifying :<port>. For example, this will listen for both ipv4 and ipv6 sockets on all hosts on port 8080:

python --bind :8080

Use this notation when running pulsar inside Docker or any other container.

You can bind to a random available port by specifying 0 as the port number:

python --bind :0

useful during testing.


To specify the maximum number of queued connections you can use the backlog settings. For example:

python --backlog 1000

rarely used.


To control how long a server Connection is kept alive after the last read from the remote client, one can use the keep-alive setting:

python --keep-alive 10

will close client connections which have been idle for 10 seconds.

TLS/SSL support

Transport Layer Security (often known as Secure Sockets Layer) is handled by the cert-file and key-file settings:

python --cert-file server.crt --key-file server.key


When running a SocketServer in multi-process mode (default), the application, create a listening socket in the parent (Arbiter) process and then spawn several process-based actors which listen on the same shared socket. This is how pre-forking servers operate.

When running a SocketServer in threading mode:

python --concurrency thread

the number of Actor serving the application is set to 0 so that the application is actually served by the arbiter event-loop (we refer this to a single process server). This configuration is used when debugging, testing, benchmarking or on small load servers.

In addition, a SocketServer in multi-process mode is only available for:

  • Posix systems.
  • Windows running python 3.2 or above (python 2 on windows does not support the creation of sockets from file descriptors).

Check the SocketServer.monitor_start() method for implementation details.


Socket Server

class pulsar.apps.socket.SocketServer(callable=None, load_config=True, **params)[source]

A Application which serve application on a socket.

It bind a socket to a given address and listen for requests. The request handler is constructed from the callable passed during initialisation.


The socket address, available once the application has started.

create_server(worker, protocol_factory, address=None, sockets=None, idx=0)[source]

Create the Server which will listen for requests.

Returns:a TcpServer.

Create the socket listening to the bind address.

If the platform does not support multiprocessing sockets set the number of workers to 0.


Factory of ProtocolConsumer used by the server.

By default it returns the Application.callable().


alias of TcpServer

support_ssl = <module 'ssl' from '/usr/lib/python3.5/'>
worker_start(worker, exc=None)[source]

Start the worker by invoking the create_server() method.

UDP Socket Server

class pulsar.apps.socket.UdpSocketServer(callable=None, load_config=True, **params)[source]

A SocketServer which serves application on a UDP sockets.

It binds a socket to a given address and listen for requests. The request handler is constructed from the callable passed during initialisation.


Return the DatagramProtocol factory.