|
| 1 | +# Classical Client-Server example |
| 2 | + |
| 3 | +Very simple example to demonstrate how to write client-server applications which exchange |
| 4 | +classical messages. |
| 5 | + |
| 6 | + |
| 7 | +# How to run |
| 8 | + |
| 9 | +There are two ways to run this example: |
| 10 | + |
| 11 | + |
| 12 | +## On a single machine |
| 13 | + |
| 14 | +The simplest way to run this example is on a single machine. To do this, you can use the |
| 15 | +provided bash script: |
| 16 | + |
| 17 | +```shell |
| 18 | +./run.sh |
| 19 | +``` |
| 20 | + |
| 21 | +Alternatively, you can manually start the client and teh server in two different terminals. |
| 22 | +First, start the server on one terminal |
| 23 | + |
| 24 | +```shell |
| 25 | +python example_server_alice.py |
| 26 | +``` |
| 27 | + |
| 28 | +which start the server and keeps listening for new incoming connections. Then start the client: |
| 29 | + |
| 30 | +```shell |
| 31 | +python example_client_bob.py |
| 32 | +``` |
| 33 | + |
| 34 | +which will connect to the server and send a message that will be sent back by the server. |
| 35 | + |
| 36 | + |
| 37 | +## On different machines |
| 38 | + |
| 39 | +To run this example on different machines, it is necessary that both machines can reach each |
| 40 | +other via a network (or the internet). Additionally, you need to know the IP addresses of both |
| 41 | +machines. |
| 42 | + |
| 43 | +Assuming that the server (alice) will run on a machine with IP `192.168.0.1` and the client (bob) |
| 44 | +will run on the machine with IP `192.168.0.2`, modify the `simulaqron_network.json` file *on both* |
| 45 | +the server and the client to look like this: |
| 46 | + |
| 47 | +```json |
| 48 | +[ |
| 49 | + { |
| 50 | + "name": "default", |
| 51 | + "nodes": [ |
| 52 | + { |
| 53 | + "Alice": { |
| 54 | + "app_socket": ["192.168.0.1", 8821], |
| 55 | + "qnodeos_socket": ["192.168.0.1", 8822], |
| 56 | + "vnode_socket": ["192.168.0.1", 8823] |
| 57 | + } |
| 58 | + }, |
| 59 | + { |
| 60 | + "Bob": { |
| 61 | + "app_socket": ["192.168.0.2", 9831], |
| 62 | + "qnodeos_socket": ["192.168.0.2", 9832], |
| 63 | + "vnode_socket": ["192.168.0.2", 9833] |
| 64 | + } |
| 65 | + } |
| 66 | + ], |
| 67 | + "topology": null |
| 68 | + } |
| 69 | +] |
| 70 | +``` |
| 71 | + |
| 72 | +Note that the `localhost` entries from Alice were changed to `192.168.0.1`. Similarly, the |
| 73 | +`localhost` entries from Bob were changed to `192.168.0.2`. |
| 74 | + |
| 75 | +After these modifications, start the server and client in their respective terminals as described |
| 76 | +before. |
0 commit comments