From 2a097dfaf8b0f09efd363b6b18efd6c8bec8aad1 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 15 Feb 2018 06:17:07 +0545 Subject: [PATCH] examples: import client/server.py test scripts as examples --- examples/service/client.py | 17 +++++++++++++++++ examples/service/server.py | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 examples/service/client.py create mode 100644 examples/service/server.py diff --git a/examples/service/client.py b/examples/service/client.py new file mode 100644 index 00000000..929016c1 --- /dev/null +++ b/examples/service/client.py @@ -0,0 +1,17 @@ + +import socket + +import mitogen.master +import mitogen.unix +import mitogen.service +import mitogen.utils + + +PING = 500 + + +mitogen.utils.log_to_file() + +router, parent = mitogen.unix.connect('/tmp/mitosock') +with router: + print mitogen.service.call(parent, CONNECT_BY_ID, {}) diff --git a/examples/service/server.py b/examples/service/server.py new file mode 100644 index 00000000..659e677c --- /dev/null +++ b/examples/service/server.py @@ -0,0 +1,25 @@ + +# The service framework will fundamentally change (i.e. become much nicer, and +# hopefully lose those hard-coded magic numbers somehow), but meanwhile this is +# a taster of how it looks today. + +import time + +import mitogen +import mitogen.service +import mitogen.unix + + +class PingService(mitogen.service.Service): + well_known_id = 500 + max_message_size = 1000 + + def dispatch(self, dct, msg): + return 'Hello, world' + + +@mitogen.main() +def main(router): + listener = mitogen.unix.Listener(router, path='/tmp/mitosock') + service = PingService(router) + service.run()