如何获取客户端IP地址? [英] how to get client ip address?

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

问题描述

我想知道如何在socket(java)中知道服务器端客户端的IP地址。假设有一个服务器S和2个客户端A和B。客户端A向我(服务器)发送一些信息,客户端B向我(服务器)发送一些其他信息。我必须将来自A和B的信息存储在不同表中的数据库中。如何区分客户端A和B请求。

I want to know that how can we know the IP address of client on server side in socket (java). Suppose there is a server "S" and 2 clients "A" and "B". Client A send me(server) some info, and Client B send me(server) some other info. I have to store that info coming from A and B in database in different tables. How can I Differentiate between client A and B request.?

推荐答案

每个套接字都有 getInetAddress() 方法,它返回连接到它的客户端的IP地址。

Each socket has a getInetAddress() method which returns the IP address of the client connected to it.

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

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