Use JSON protocol at directory

The directory now uses a JSON protocol analogous to that used by the
router.  Methods are "connect", "disconnect", "list" and "discover".
Fields are "port" (connect/disconnect/discover) and "num"
(list/discover), both of which should be integers.