18

Practice

Make sure the magic bus demon is running with ps -ef|grep mbd. If necessary, start the service with the command /usr/local/etc/mbd. If mbd displays the error message Address already in use, delete the file /tmp/magicbus and restart the program.

Enter /usr/local/etc/mbping -P"ping> " in a separate terminal window.

$ /usr/local/etc/mbping -P"ping> "
MagicBus Ping 2.0 (1)
(C)2010 frasq.org.
ping>

Enter help at the prompt.

ping> help
bind [host]
register app_name [sync]
probe app_name [sync]
1 app_name msg
2 app_name msg
send app_name count char
msend app_name count char
dumpsize [n_octets]
pagesize [n_octets]
sleep nsecs
unbind
exit | quit
quit | exit
ping>

It is not necessary to type the entire name of a command. If your input is ambiguous, a help message is displayed.

ping> s
send app_name count char
sleep nsecs
ping>

Enter b to open a connection with the bus.

ping> b
ping>

If the command prints an error message, enter /usr/local/etc/mbd to start the demon of the magic bus.

ping> b
No such file or directory
ping>

In another terminal, enter /usr/local/etc/mbping -P"pong> ".

MagicBus Ping 2.0 (1)
(C)2010 frasq.org.
pong>

Enter b to bind the process to the bus then re pong t to register it as pong.

pong> b
pong> re pong t
1
pong>

The command returns 1 which means that one process is currently registered as pong.

Go back to the first mbping process and enter pr pong.

ping> pr pong t
1
ping>

Enter 1 pong Hello my dear pong! to send a one-way message to the pong process.

ping> 1 pong Hello, my dear pong!
ping>
[1]SENT

The bus returns a positive confirmation. The message is dumped by pong.

pong> 
[0]<21>
0000 48 65 6c 6c 6f 2c 20 6d 79 20 64 65 61 72 20 70 Hello, my dear p
0016 6f 6e 67 21 00                                  ong!.

Go back to the first mbping process and enter 2 pong You could be nicer. to send a two-way message to the pong process.

ping> 2 pong You could be nicer.
ping>
[2]<20>
0000 59 6f 75 20 63 6f 75 6c            64 20 62 65 20 6e 69 63 You could be nic
0016 65 72 2e 00                                                er..

The message is dumped by pong and returned to the sender. Note: When a two-way message is sent, the receiver is expected to send a reply. mbping echoes whatever it receives.

Enter 2 ping I’m sorry. at the prompt of the second mbping process.

pong> 2 ping I'm sorry.
pong>
[2]NOBODY

The bus returns a negative confirmation meaning that no process is currently registered as ping.

Go back to the first mbping process and enter re ping.

ping> re ping
ping>
1

Now try again 2 ping I’m sorry. from pong.

pong> 2 ping I'm sorry.
pong>
[3]<11>
0000 49 27 6d 20 73 6f 72 72            79 2e 00         I'm sorry..

Block the pong process by entering a sleep command.

pong> sleep 90

Now quickly send a two-way message from the ping process.

ping> 2 pong Are you there?
ping>

The message isn’t read by pong which is asleep. Notice that ping isn’t blocked by waiting for the reply because communications with the bus are asynchronous. After a time-out delay, the bus automatically sends ping an error message. Note: The default time-out is 60 seconds. It can be set from the command-line when mbd is launched

ping>
[4]TIMEOUT

When pong wakes up after 90 seconds, it reads the message and sends a reply, but it is too late and the bus simply ignores it.

Go back to the ping process and enter se pong 10240 @.

ping> se pong 10240 @
ping>
[5]SENT

A one-way message consisting of 10,240 @ is received by the pong process.

pong>
[0]<10240>
0000 40 40 40 40 40 40 40 40             40 40 40 40 40 40 40 40 @@@@@@@@@@@@@@@@
0016 40 40 40 40 40 40 40 40             40 40 40 40 40 40 40 40 @@@@@@@@@@@@@@@@

The default length of a dump is limited to 32 bytes. You can use the dumpsize command to change it.

Enter se ping 1024000 % at the prompt of the pong process.

pong> se ping 1024000 %
pong>
[4]SENT

A message consisting of 1,024,000 % is received by the ping process.

ping>
[0]<1024000>
0000 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 %%%%%%%%%%%%%%%%
0016 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 %%%%%%%%%%%%%%%%

In another terminal, enter /usr/local/etc/mbping -P"pong> ".

MagicBus Ping 2.0 (1)
(C)2010 frasq.org.
pong>

Enter b to bind the process to the bus then re pong t to register it as pong.

pong> b
pong> re pong t
2
pong>

There are now two processes registered as pong.

Enter se pong 1024 $ at the prompt of the ping process. The message is still received by the first pong. The second pong doesn’t receive anything.

Enter mse pong 1024 # at the prompt of the ping process. The message is broadcast. It is received by both pong processes.

Enter quit at the prompt of the first pong process, then try se pong 1024 $ at the prompt of the ping process. The message is automatically redirected to the second pong process.

Quit ping and pong.

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].