Skip to content

Commit 7257e1e

Browse files
committed
Merge pull request socketio#329 from 3rd-Eden/remoteAddress
.address() returned server ip >_<, solved with this patch and adjusted th
2 parents c18aa40 + af5960b commit 7257e1e

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

lib/manager.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/*!
23
* socket.io-node
34
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
@@ -819,10 +820,16 @@ Manager.prototype.handshakeData = function (data) {
819820
var connection = data.request.connection
820821
, connectionAddress;
821822

822-
if (connection.address) {
823-
connectionAddress = connection.remoteAddress; // Bug fix, returns client IP instead of .address() which was returning server IP
824-
} else if (connection.socket && connection.socket.address) {
825-
connectionAddress = connection.socket.address(); // Do we need .remoteAddress here too?
823+
if (connection.remoteAddress) {
824+
connectionAddress = {
825+
address: connection.remoteAddress
826+
, port: connection.remotePort
827+
};
828+
} else if (connection.socket && connection.socket.remoteAddress) {
829+
connectionAddress = {
830+
address: connection.socket.remoteAddress
831+
, port: connection.socket.remotePort
832+
};
826833
}
827834

828835
return {

test/namespace.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ module.exports = {
8080
fn(null, true);
8181
})
8282
.on('connection', function (socket) {
83-
socket.handshake.address.address.should.equal('127.0.0.1');
84-
socket.handshake.address.port.should.equal(ports);
83+
(!!socket.handshake.address.address).should.be.true;
84+
(!!socket.handshake.address.port).should.be.true;
8585
socket.handshake.headers.host.should.equal('localhost');
8686
socket.handshake.headers.connection.should.equal('keep-alive');
8787
socket.handshake.time.should.match(/GMT/);

test/transports.websocket.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,8 +1493,8 @@ module.exports = {
14931493
, ws;
14941494

14951495
io.sockets.on('connection', function (socket) {
1496-
socket.handshake.address.address.should.equal('127.0.0.1');
1497-
socket.handshake.address.port.should.equal(ports);
1496+
(!!socket.handshake.address.address).should.be.true;
1497+
(!!socket.handshake.address.port).should.be.true;
14981498
socket.handshake.headers.host.should.equal('localhost');
14991499
socket.handshake.headers.connection.should.equal('keep-alive');
15001500
socket.handshake.time.should.match(/GMT/);

0 commit comments

Comments
 (0)