bash-com/README.md

45 lines
1.4 KiB
Markdown
Raw Normal View History

2018-01-27 18:09:31 +00:00
# Exemple
2 machines (A and B) want to share an INPUT/OUTPUT communication in bash.
- Machine B: 10.10.10.10 port 1111
- Machine A: 20.20.20.20 port 2222
### On machine B
First of all because each machine will launch a **client** and a **server**, because of cyclic-redondency, we have to synchronise them so that the _clients_ are connected after the 2 _servers_.
We can use the 'trigger' to do such synchronisation. It waits until it receives (through a choosen port) a message from machine A.
```bash
./trigger 9999; ./launch machineB 20.20.20.20 2222 1111
```
So we are listening on port _9999_ waiting for machine A to tell us when to start.
The arguments can be read through this sentence "I will connect to `20.20.20.20` at port `2222` and my port `1111` is available."
### On machine A
You can notice that it is the reverse command from machine B, but we have to launch the trigger instead of waiting for it. The last optional parameter of 'launch' is made for that purpose.
```bash
./launch machineA 10.10.10.10 1111 2222 9999;
```
Now the server will start as expected and stop the 'trigger' command on machine B so it will also launch the server on it. After a delay of 2 seconds, the 2 servers might be connected to each other.
### Send a message
```bash
./write {sender_machine} "some_message\n";
```
### Read messages
```bash
./read {sender_machine};
```
Note: After a 'read' call, the buffer will be flushed (reading = consuming).