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

前端 未结 4 1576
傲寒
傲寒 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:18

    Use this code :

    String ip=(((InetSocketAddress) socket.getRemoteSocketAddress()).getAddress()).toString().replace("/","");
    

提交回复
热议问题