-
Notifications
You must be signed in to change notification settings - Fork 22
Expensive to synchronously set TCPSocket.localAddress when using default local address #24
Comments
This is ok if there are no use cases for an application to retrieve the IP-address of the default local interface and/or the randomly selected local port number. |
Ok, so this means that the socket constructor sets the TCPSocket.localAddress and TCPSocket.localPort attributes to null if no explicit values were set with the options argument's localAddress and localPort members. Otherwise these attributes are set to the values given by these members. |
How about that : localAddress and localPort are set to both NULL if not specified by constructor, or to values given to constructor if any. When in "open" readystate, they are both guaranteed to be set to actual values. In particular, when "onopen" callback is serviced localAddress and localPort contain the actual values. Note that we need to add a mean to get a list of all available network interface(s). |
I think that this is a reasonable solution. WDYT Jonas? The ability to get a a list of all available network interface(s) sounds like a separate API. |
For the list network interface(s), I think it should be part of the raw-socket API. http://www.nodejs.org/api/os.html#os_os_networkinterfaces For NodeJS, that's just a function returning an array. |
Mounir worked on a W3C network API It provides informations on a specific network but don't expose adress There is also the Network Service Discovery: |
Specifically on a socket object, what is the use case for knowing the local IP address? Do a lot of protocols that go over TCP/UDP require sending the local IP address to the other end? Or do they require comparing incoming data to the local IP address? Does anyone have examples of this? I definitely agree that there should be a way to get the local IP addresses and interfaces. However it still strikes me as odd to make that live on the socket connection object. So I'd rather that the properties on the connection object simply reflect the values that were passed to the constructor. And then create an API like the node.js one mentioned above. |
There are two issues:
|
For issue 1, I assume that extending the W3C DAP Network Information API, http://www.w3.org/TR/netinfo-api/, with information on available network interfaces would have privacy implications. |
Currently the API requires the implementation to be able to synchronously get the default local address. Consider the following code:
var tcp = new TCPSocket("123.123.123.123", 4711);
console.log(tcp.localAddress);
This forces the implementation to block the execution of the TCPSocket constructor until the implementation has read the default local address, something which likely requires some amount of IO.
I propose that the TCPSocket.localAddress and TCPSocket.localPort are set to whatever explicit value was passed to the constructor, or null if no value was set.
Same applies to UDPSocket.
The text was updated successfully, but these errors were encountered: