… | |
… | |
762 | aemp run profile seed |
762 | aemp run profile seed |
763 | |
763 | |
764 | And then you can experiment with chatting, killing one or more clients, or |
764 | And then you can experiment with chatting, killing one or more clients, or |
765 | stopping and restarting the server, to see the monitoring in action. |
765 | stopping and restarting the server, to see the monitoring in action. |
766 | |
766 | |
|
|
767 | The crucial point you should understand from this example is that |
|
|
768 | monitoring is usually symmetric: when you monitor some other port, |
|
|
769 | potentially on another node, that other port usually should monitor you, |
|
|
770 | too, so when the connection dies, both ports get killed, or at least both |
|
|
771 | sides can take corrective action. Exceptions are "servers" that serve |
|
|
772 | multiple clients at once and might only wish to clean up, and supervisors, |
|
|
773 | who of course should not normally get killed (unless they, too, have a |
|
|
774 | supervisor). |
|
|
775 | |
|
|
776 | If you often think in object-oriented terms, then treat a port as an |
|
|
777 | object, C<port> is the constructor, the receive callbacks set by C<rcv> |
|
|
778 | act as methods, the C<kil> function becomes the explicit destructor and |
|
|
779 | C<mon> installs a destructor hook. Unlike conventional object oriented |
|
|
780 | programming, it can make sense to exchange ports more freely (for example, |
|
|
781 | to monitor one port from another). |
|
|
782 | |
767 | There is ample room for improvement: the server should probably remember |
783 | There is ample room for improvement: the server should probably remember |
768 | the nickname in the C<join> handler instead of expecting it in every chat |
784 | the nickname in the C<join> handler instead of expecting it in every chat |
769 | message, it should probably monitor itself, and the client should not try |
785 | message, it should probably monitor itself, and the client should not try |
770 | to send any messages unless a server is actually connected. |
786 | to send any messages unless a server is actually connected. |
771 | |
787 | |