How to find the IP Address of Client connected to Server?

前端 未结 4 1569
傲寒
傲寒 2020-12-13 18:38

My client pc is connected to as server pc via sockets over Ethernet, How do I find the IP of this client from the server side code.
The server is dishing out one socket

相关标签:
4条回答
  • 2020-12-13 19:15

    I think you might be looking for the getInetAddress method of the Socket object.

    0 讨论(0)
  • 2020-12-13 19:15

    Use getRemoteSocketAddress() instead.

    0 讨论(0)
  • 2020-12-13 19:18

    Use this code :

    String ip=(((InetSocketAddress) socket.getRemoteSocketAddress()).getAddress()).toString().replace("/","");
    
    0 讨论(0)
  • 2020-12-13 19:22

    I believe you want to use the remote address instead:

    csocket.getRemoteSocketAddress().toString();
    
    0 讨论(0)
提交回复
热议问题