aboutsummaryrefslogtreecommitdiff
path: root/jsonrpc/examples/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'jsonrpc/examples/client.py')
-rw-r--r--jsonrpc/examples/client.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/jsonrpc/examples/client.py b/jsonrpc/examples/client.py
new file mode 100644
index 0000000..14b3cf9
--- /dev/null
+++ b/jsonrpc/examples/client.py
@@ -0,0 +1,59 @@
+import socket
+import random
+import json
+
+HOST = "127.0.0.1"
+PORT = 60000
+
+s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+s.connect((HOST, PORT))
+
+req = {
+ "jsonrpc": "2.0",
+ "id": str(random.randint(0, 1000)),
+ "method": "Calc.add",
+ "params": {"x": 4, "y": 3},
+}
+print("Send: ", req)
+s.sendall(json.dumps(req).encode())
+res = s.recv(1024)
+res = json.loads(res)
+print("Received: ", res)
+
+req = {
+ "jsonrpc": "2.0",
+ "id": str(random.randint(0, 1000)),
+ "method": "Calc.sub",
+ "params": {"x": 4, "y": 3},
+}
+print("Send: ", req)
+s.sendall(json.dumps(req).encode())
+res = s.recv(1024)
+res = json.loads(res)
+print("Received: ", res)
+
+req = {
+ "jsonrpc": "2.0",
+ "id": str(random.randint(0, 1000)),
+ "method": "Calc.ping",
+ "params": None,
+}
+print("Send: ", req)
+s.sendall(json.dumps(req).encode())
+res = s.recv(1024)
+res = json.loads(res)
+print("Received: ", res)
+
+req = {
+ "jsonrpc": "2.0",
+ "id": str(random.randint(0, 1000)),
+ "method": "Calc.version",
+ "params": None,
+}
+print("Send: ", req)
+s.sendall(json.dumps(req).encode())
+res = s.recv(1024)
+res = json.loads(res)
+print("Received: ", res)
+
+s.close()