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 per client in a new Thread.
When I do a csocket.getLocalAddress().toString()
on the client socket I still get the Server IP address. ( csocket
is the socket that the Server has spawned upon a now client connection and passed it to a new Thread).
我相信你想要使用远程地址 :
csocket.getRemoteSocketAddress().toString();
我想你可能正在寻找Socket对象的getInetAddress方法。
使用此代码:
String ip=(((InetSocketAddress) socket.getRemoteSocketAddress()).getAddress()).toString().replace("/","");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.