So in the previous exercise we've made our p2p chat app work. Woo!! As you'd probably noticed its quite annoying to have to type all those hostnames and ports all the time.
Wouldn't it be great if you could just connect to your friends by typing their username?
Luckily we can easily add that by using the same multicast dns tricks as we used in exercise 4.
Remember that your can register a multicast dns using the register-multicast-dns module and add support for looking up domains using lookup-multicast-dns
To choose a port based on a username you can use the hash-to-port module. For example to map a username to a multicast dns domain and port you could do
var hashToPort = require('hash-to-port')
function toAddress (username) {
return username + '.local:' + hashToPort(username)
}
Run your chat server in your terminal like so
node {your-nickname} {another-nickname}
And in another one
node {another-nickname} {your-nickname}
If you type in the first one your chat messages should show up in the second one.
When you are done click here to go to the next exercise