You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The way we lookup server addresses and socket addresses is not quite correct, and we should only listen on ip4. It means that although everything works on localhost, and works in tests, I do not think that everything will work as expected on a real network.
server.address() as used here returns the address that the server is bound to by the OS. Since we create the server with no options, this will default to 0.0.0.0 on ip4 and :: on ip6. On an OS that supports ip6 (my Mac for instance) server.address().address will be ::. We are using this as the host name that we are advertising on mdns.
We should not pass a hostname to mdns, and instead rely on the mdns module to create a correct hostname (which will be a .local address) for the mdns record. In addition we should probably specify server.listen({ host: '0.0.0.0', port: 0 }) to force the server to only listen on ip4, but to listen on all addresses (e.g. local and non-local).
For connecting to a peer when discovering a service via mdns, we use the service.host property. This will be hostname.local. normally, but since we are specifying hostwhen we advertise the service it will be either :: or 0.0.0.0. This will work in tests (since connecting to this will work locally) it will not work on a real network. We should use the addresses property of the resolved service record. This will always have at least one entry, and any of the entries should work for connecting.
For the address of an incoming connection from a peer, we use socket.address(). This will not be the address of the peer, but rather be the locally bound address - the same same as returned by server.address(). To get the address of the incoming connection we need socket.remoteAddress and socket.remotePort.
The text was updated successfully, but these errors were encountered:
The way we lookup server addresses and socket addresses is not quite correct, and we should only listen on ip4. It means that although everything works on localhost, and works in tests, I do not think that everything will work as expected on a real network.
server.address()
as used here returns the address that the server is bound to by the OS. Since we create the server with no options, this will default to0.0.0.0
on ip4 and::
on ip6. On an OS that supports ip6 (my Mac for instance)server.address().address
will be::
. We are using this as the host name that we are advertising on mdns.We should not pass a hostname to mdns, and instead rely on the mdns module to create a correct hostname (which will be a
.local
address) for the mdns record. In addition we should probably specifyserver.listen({ host: '0.0.0.0', port: 0 })
to force the server to only listen on ip4, but to listen on all addresses (e.g. local and non-local).For connecting to a peer when discovering a service via mdns, we use the service.host property. This will be
hostname.local.
normally, but since we are specifyinghost
when we advertise the service it will be either::
or0.0.0.0
. This will work in tests (since connecting to this will work locally) it will not work on a real network. We should use theaddresses
property of the resolvedservice
record. This will always have at least one entry, and any of the entries should work for connecting.For the address of an incoming connection from a peer, we use
socket.address()
. This will not be the address of the peer, but rather be the locally bound address - the same same as returned byserver.address()
. To get the address of the incoming connection we needsocket.remoteAddress
andsocket.remotePort
.The text was updated successfully, but these errors were encountered: