When using socket.IO in a Node.js server, is there an easy way to get the IP address of an incoming connection? I know you can get it from a standard HTTP connection, but socket.io is a bit of a different beast.
var socket = require('socket. io-client')('ws://ws.website.com/socket.io/?EIO=3&transport=websocket'); socket. on('connect', function() { console. log("Successfully connected!"); });
The Socket instance (client-side) | Socket.IO.
Use Monitor.io to observe connections and replay messages When you add it to your Node. js application, it provides a monitoring interface that you can access remotely by opening a Telnet connection to a particular port. It shows a list of active Socket.io client connections for your application.
Okay, as of 0.7.7 this is available, but not in the manner that lubar describes. I ended up needing to parse through some commit logs on git hub to figure this one out, but the following code does actually work for me now:
var io = require('socket.io').listen(server); io.sockets.on('connection', function (socket) { var address = socket.handshake.address; console.log('New connection from ' + address.address + ':' + address.port); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With