OK, lets try this in smaller more informative commits.
Here's the first of a sequence of pull requests. This one only adds the ability to send to a named@server
It expects back from the server a JSON with an address key or one with "error"/"errcode" in which case it throws an error in RPC. There is an example implementation of the server code in contrib/ns/ which can be installed.