diff options
author | Stavros Korokithakis <hi@stavros.io> | 2018-12-07 18:17:52 +0200 |
---|---|---|
committer | Stavros Korokithakis <hi@stavros.io> | 2018-12-07 18:17:52 +0200 |
commit | 0aca0ae50a7336c705a92f2444d6fcd1b3e283e9 (patch) | |
tree | c2406feab14ce3c9a24dadb324472ef815e1859e | |
parent | 4f63fe74a96d7f642147a445a04a29b8808fa5b5 (diff) | |
download | pysignald-0aca0ae50a7336c705a92f2444d6fcd1b3e283e9.tar.gz pysignald-0aca0ae50a7336c705a92f2444d6fcd1b3e283e9.zip |
Support TCP sockets
-rw-r--r-- | README.md | 22 | ||||
-rw-r--r-- | signald/main.py | 7 |
2 files changed, 28 insertions, 1 deletions
@@ -38,3 +38,25 @@ s.send_message("+1098765432", "Hello there!") for message in s.receive_messages(): print(message) ``` + + +Various +------- + +pysignald also supports different socket paths: + +```python +s = Signal("+1234567890", socket_path="/var/some/other/socket.sock") +``` + +It supports TCP sockets too, if you run a proxy. For example, you can proxy signald's UNIX socket over TCP with socat: + +```bash +$ socat -d -d TCP4-LISTEN:15432,fork UNIX-CONNECT:/var/run/signald/signald.sock +``` + +Then in pysignald: + +```python +s = Signal("+1234567890", socket_path=("your.serveri.ip", 15432)) +``` diff --git a/signald/main.py b/signald/main.py index 2c12322..cfad0e8 100644 --- a/signald/main.py +++ b/signald/main.py @@ -32,7 +32,12 @@ class Signal: def _get_socket(self) -> socket.socket: "Create a socket, connect to the server and return it." - s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + + # Support TCP sockets on the sly. + if isinstance(self.socket_path, tuple): + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + else: + s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.connect(self.socket_path) return s |