From f660be5fd3cf279f2da4b6d52aa76afb3cb5b77a Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 8 Dec 2018 14:47:07 +0000 Subject: [PATCH] Add some examples to readme --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/README.md b/README.md index 438fedb..a3c4aae 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,42 @@ [![CircleCI](https://circleci.com/gh/RealOrangeOne/ipc-unix.svg?style=svg)](https://circleci.com/gh/RealOrangeOne/ipc-unix) Simple Inter-Process Communication using unix sockets for Python. + + +## Examples + +### Call / Response + +```python +from ipc_unix import Server, Client + +class EchoServer(Server): + def handle_request(self, request): + return request + +socket_path = '/tmp/sock.sock' +server = EchoServer(socket_path) +client = Client(socket_path) + +print(client.send({"foo": "bar"})) +>>> {"foo": "bar"} + +``` + +### Pub-Sub + +```python +from ipc_unix import pubsub + +socket_path = '/tmp/sock.sock' +publisher = pubsub.Publisher(socket_path) +subscriber = pubsub.Subscriber(socket_path) + +publisher.write({"foo": "bar"}) +print(self.subscriber.get_latest_message()) +>>> {"foo": "bar"} + +publisher.close() +subscriber.close() + +```