Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

net: make .address() work for client sockets

  • Loading branch information...
commit 1b0994de81cd2748e51c735f1e68573ba4cbdfe7 1 parent 7defbd2
@bnoordhuis authored
Showing with 12 additions and 12 deletions.
  1. +9 −10 lib/net.js
  2. +3 −2 test/simple/test-net-remote-address-port.js
View
19 lib/net.js
@@ -164,8 +164,15 @@ Socket.prototype.setKeepAlive = function(setting, msecs) {
};
+// Also used by Server.prototype.address()
Socket.prototype.address = function() {
- return this._handle.getsockname();
+ if (this._handle && this._handle.getsockname) {
+ return this._handle.getsockname();
+ } else if (this._pipeName) {
+ return this._pipeName;
+ } else {
+ return null;
+ }
};
@@ -768,15 +775,7 @@ Server.prototype.listen = function() {
return self;
};
-Server.prototype.address = function() {
- if (this._handle && this._handle.getsockname) {
- return this._handle.getsockname();
- } else if (this._pipeName) {
- return this._pipeName;
- } else {
- return null;
- }
-};
+Server.prototype.address = Socket.prototype.address;
function onconnection(clientHandle) {
var handle = this;
View
5 test/simple/test-net-remote-address-port.js
@@ -15,12 +15,13 @@ var server = net.createServer(function(socket) {
});
});
-server.listen(common.PORT, 'localhost', function() {
- var client = net.createConnection(common.PORT, 'localhost');
+server.listen(common.PORT, '127.0.0.1', function() {
+ var client = net.createConnection(common.PORT, '127.0.0.1');
var client2 = net.createConnection(common.PORT);
client.on('connect', function() {
assert.equal('127.0.0.1', client.remoteAddress);
assert.equal(common.PORT, client.remotePort);
+ assert.equal('127.0.0.1', client.address().address); // local address
client.end();
});
client2.on('connect', function() {
Please sign in to comment.
Something went wrong with that request. Please try again.