bash-com/README.md

1.4 KiB

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.

./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.

./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

./write {sender_machine} "some_message\n";

Read messages

./read {sender_machine};

Note: After a 'read' call, the buffer will be flushed (reading = consuming).