如何查找连接到服务器的客户端的IP地址? [英] How to find the IP Address of Client connected to Server?

查看:569
本文介绍了如何查找连接到服务器的客户端的IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的客户端电脑通过以太网上的套接字连接到服务器电脑,如何从服务器端代码中找到该客户端的IP。

服务器在每个客户端发送一个插槽新线程。

当我在客户端套接字上执行 csocket.getLocalAddress()。toString()时,我仍然获得服务器IP地址。 ( csocket 是服务器在现在客户端连接上生成并将其传递给新线程的套接字。

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();

这篇关于如何查找连接到服务器的客户端的IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆