mrniko / netty-socketio

Socket.IO server implemented on Java. Realtime java framework
Apache License 2.0
6.82k stars 1.65k forks source link

How to detact client IP Address #339

Open PeterL1n opened 8 years ago

PeterL1n commented 8 years ago

Is there way to obtain the ip address of the client? That would be really useful.

JavaMachine commented 8 years ago

socketIOClient.getRemoteAddress(); //Here is you Client IP

pgamaster commented 8 years ago

This will not work behind a proxy server like nginx.

How can I parse headers like X-Forwarded-For or X-Real-IP ? In nodejs is works like: var ip = socket.handshake.headers['x-real-ip'];

How can I implement it in netty-socketio?

UPDATE: it is simple :+1: String ip = client.getHandshakeData().getSingleHeader("X-Real-IP");