Skip to content

Official way for getting IP of socket #566

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

Closed
ghost opened this issue Dec 4, 2018 · 3 comments
Closed

Official way for getting IP of socket #566

ghost opened this issue Dec 4, 2018 · 3 comments
Labels
question Further information is requested

Comments

@ghost
Copy link

ghost commented Dec 4, 2018

There are Socket.io v2 and Engine.io v3 and (still O_O) there is not any official way for getting IP of connection. Why? It is one of the most needed feature.

@ghost ghost changed the title Standard way for getting IP of socket Official way for getting IP of socket Dec 4, 2018
@darrachequesne
Copy link
Member

Hmm... it seems you are looking for socket.handshake.address (ref) :

io.on('connection', (socket) => {
  let ip = socket.handshake.address;
  // ...
});

As usual, if you find ways to improve the documentation, please do open a PR! 👍

@ghost
Copy link
Author

ghost commented Dec 4, 2018

I will, thanks for reply. The big problems are posts around the web about "this is a problem" and provided solutions that sometimes work, in some version of eio/sio work etc. so together with hole in documentation it makes me to post and issue here.

I've already found by consolelogging socket object that socket itself has remoteAddress property that contains correct (in my situation) IP, is it safe way? Or I should use socket.handshake.address?

@darrachequesne
Copy link
Member

socket.handshake.address should actually be equal to the remoteAddress attribute:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant