Remote address (IP) is always undefined
See original GitHub issueAfter 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:
require('socket.io')(8888).on('connection', socket => {
console.log('socket.client.conn.remoteAddress', socket.client.conn.remoteAddress);
console.log('socket.request.connection.remoteAddress', socket.request.connection.remoteAddress);
console.log('socket.handshake.address', socket.handshake.address);
});
Client:
<script src="http://192.168.13.13:8888/socket.io/socket.io.js"></script>
<script>
var socket = io('http://192.168.13.13:8888', { transports: [ 'websocket' ] });
socket.on('connect', function(){
console.log('connected');
});
</script>
Aaaaand it’s gone.
daniil@ubuntu:/var/srv/node-test# node server.js
socket.client.conn.remoteAddress undefined
socket.request.connection.remoteAddress undefined
socket.handshake.address undefined
When I remove { transports: [ 'websocket' ] }
from client’s code, I got this:
socket.client.conn.remoteAddress ::ffff:192.168.13.12
socket.request.connection.remoteAddress ::ffff:192.168.13.12
socket.handshake.address ::ffff:192.168.13.12
Socket.io 1.7.4 works fine. Socket.io >=2.0.1 is not.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:13
- Comments:16 (2 by maintainers)
Top Results From Across the Web
Socket.io - Getting client's IP always results in undefined
Since my comment worked for you, I'll put it in an answer. socket.request.connection.remoteAddress is the supported way to get the remote IP ...
Read more >Net | Node.js v19.3.0 Documentation
The string representation of the remote IP address. For example, '74.125.127.100' or '2001:4860:a005::68' . Value may be undefined if the socket is ...
Read more >request-ip
A small Node.js module to retrieve the request's IP address. ... Start using request-ip in your project by running `npm i request-ip`.
Read more >How to get a client IP Address in Node.js (6 ways)
Retrieve User IP Address From the Request Object's Socket Property. First up, we find the request's IP address with a simple vanilla Node...
Read more >How To Fix the “Server IP Address Could Not Be Found” ...
The message itself tells you that the issue lies with a server's internet protocol (IP) address, but doesn't specify which end of the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Serveurperso You can also turn off IPv6 if you
http.listen(port, '0.0.0.0')
. This way your server won’t be IPv6-compatible, but also you will have remote addresses in IPv4 format. Given the fact you were going to convert IPv6 address to IPv4, IPv6 connectivity shouldn’t be an issue for you.