Servers

Servers, as the name suggests, expose services. Since RPyC is symmetric, meaning both the client and the server are essentially servers, the only distinction between the two is which is the initiator side and which is passive side. The server normally listens to a port and accepts connections by clients, and clients initiate requests to the server. This is not always the case, however.

Classic Server

The classic server, implemented in rpyc/servers/classic_server.py, is an executable script. When running it, you can specify command line options to control how it behaves:

Option Description
-m or --mode One of threaded, forking, or stdio. The default is threaded
-p or --port The TCP port on which the server listens. Applicable only for threaded and forking modes. The default is 18812
-q or --quiet Does not display any logs, except for errors. Default is verbose

Modes:

  • In the threaded mode, the server creates a thread to serve each client. This is usually the basic setup required. Supported on Windows, Linux, and most other flavors of Unix.
  • In the forking mode, the server forks a child process to serve each client. Not supported on Windows.
  • The std mode is useful for inetd invocation. In this mode, the server reads from stdin and writes to stdout instead of operating on a socket.

inetd

RPyC can easily be added to the *NIX inted daemon:

  • Add the RPyC service to /etc/services:

rpyc-classic 18812/tcp # rpyc classic mode server port

  • Add the following line to /etc/inetd.conf:

rpyc-classic stream tcp nowait some_user /usr/sbin/tcpd /usr/lib/python25/site-packages/rpyc/servers/classic_server.py -m stdio

Registry Server

The registry server is not an RPyC server at all. It's basically a name-server (like DNS, Bonjour, Avahi, etc.), which resolves a service name to a list of servers running it (hostname and port number). In order to use RPyC auto-discovery features, you will need to have a registry server running somewhere on your local network or anywhere else that can accept and respond to UDP broadcasts.

Every RPyC server, if configured with auto_register, will attempt to broadcast its details every minute to a registry server. This allows clients to automatically discover all available servers that expose a particular service.

Custom Servers

You can easily write custom servers:

from rpyc.utils.server import ThreadedServer # or ForkingServer
 
s = ThreadedServer(SomeService)
s.start()

You can also derive a class from the base class rpyc.utils.server.Server, and implement you own server from scratch.

page_revision: 11, last_edited: 1225620266|%e %b %Y, %H:%M %Z (%O ago)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License