-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remote address (IP) is always undefined #2982
Comments
@kirick13 I am experiencing the exact same behavior with |
We also experience this issue on 2.x and are unable to upgrade for now. thelounge/thelounge#1143 |
Was this fixed? As i'm having the same issue. |
@burstpay I think its still not fixed. |
Same problem here, always undefined... major issue ! |
Could you please try with engine.io v3.1.3? |
@darrachequesne How do you access that Is it correct that it should be |
Sorry, what is the proper way to upgrade my engine.io dependency from 3.1.0 to 3.1.3 ? |
I installed engine.io inside my own project and it's clean:) Now "socket.handshake.address" work but I get an ipv4-mapped IPv6address. I must parse the string (or better, upgrade my log display to ipv6) Issue close... |
@serveurperso You can also turn off IPv6 if you |
io.on('connection', function(socket){
const address = socket.handshake.headers["x-forwarded-for"].split(",")[0];
console.log(address);
}); |
@polkovnikov-ph Thanks for this great solution. Is this option somewhere documented? |
It was a long time ago, but I'm pretty sure I just made a google search with something like "http listen force ipv4" and opened first link that lead to stackoverflow. The issue is not actually related to Node.js. It's platform-specific socket behavior. Listening on |
Thanks for your prompt response. |
socket Object SERVER SIDE ! const sha_last_index_colon = socket.handshake.address.lastIndexOf(':');
if (sha_last_index_colon > -1) {
if (socket.handshake.address.lastIndexOf('.') > -1) {
socket.this_is_a_demo = {
ipv4: socket.handshake.address.slice(sha_last_index_colon + 1),
ipv6: socket.handshake.address.slice(0, sha_last_index_colon)
}
} else {
socket.this_is_a_demo = {
ipv6: socket.handshake.address
}
}
} else {
socket.this_is_a_demo = {
ipv4: socket.handshake.address
}
}
console.log(socket.this_is_a_demo.ipv4);
console.log(socket.this_is_a_demo.ipv6); |
After upgrading socket.io from 1.x.x to 2.0.3 I can't get client's IP address — it's always
undefined
.Test environment:
Ubuntu 14.04.5 LTS
Node.js 8.1.2
Socket.io 2.0.3
Server:
Client:
Aaaaand it's gone.
When I remove
{ transports: [ 'websocket' ] }
from client's code, I got this:Socket.io 1.7.4 works fine. Socket.io >=2.0.1 is not.
The text was updated successfully, but these errors were encountered: