0

i am trying to get the ip address of a remote client using nodejs, socket.io. i read here that it can be done using socket.request.connection.remoteAddress, however, how can i implement this?

and i saw the below code but i get unexpected identifier for var cleint

Var client = require('socket.io').listen(8080).sockets;
client.on('connection',function(socket){ 
var clientIpAddress= socket.request.socket.remoteAddress;
});
  • What code have you tried? It sounds like you know in general what to do, but you don't describe what happened when you tried that or show the code you tried or describe what problem you ran into when you tried it. – jfriend00 May 01 '18 at 21:25
  • well am a little new to javascript so its a little difficult for me. i edited the question and the code used? – Wolobah Gbozee May 01 '18 at 21:39

1 Answers1

0

The problem is your capital V on Var. It should be var...

Brad
  • 159,648
  • 54
  • 349
  • 530
  • thanks so much for your response, it definitely cleared that error, however its saying that the port 8080 is already being use, i guess apparently because my application runs and is accessed on that port but the goal is to get the IP address of the client accessing the web application. when i change the port on which the application runs on or the port that socket.io listens to, the code runs but cant see the output as i currently i have it set to pass the output to console, can you please point me in the right direction? – Wolobah Gbozee May 01 '18 at 22:11
  • also, i am getting 404 error when the from socket.io – Wolobah Gbozee May 01 '18 at 22:19
  • Yeah, well, something else is listening on that port so change the port to something else. – Brad May 01 '18 at 22:22
  • well like i said, i did change port and the code ran, i am however not seeing the client ip in the console long. and how is it suppose to obtain the client ip when both the application and socket.io is listening on different ports. furthermore is there anything i have to do on the client side? – Wolobah Gbozee May 01 '18 at 22:41
  • @WolobahGbozee - You need client-side code that connects to your socket.io server. – jfriend00 May 01 '18 at 23:32