查找尝试连接 ServerSocket 的程序的 IP
尽管我进行了搜索,但找不到答案。
假设我有以下 Java 代码:
ServerSocket serve = null;
try {
server = new ServerSocket(5567);
} catch (IOException e) {
System.err.println("Problem with port 5567");
System.exit(1);
}
Socket clientSocket = null;
try {
clientSocket = server.accept();
} catch (IOException e) {
System.exit(1);
}
当调用 server.accept()
时,程序会阻塞,直到有人连接到我的服务器。有没有办法找到连接到我的服务器的程序/用户的IP?
Although I searched about it I couldn't find an answer.
Let's say I have the following Java code:
ServerSocket serve = null;
try {
server = new ServerSocket(5567);
} catch (IOException e) {
System.err.println("Problem with port 5567");
System.exit(1);
}
Socket clientSocket = null;
try {
clientSocket = server.accept();
} catch (IOException e) {
System.exit(1);
}
When server.accept()
is being called the program blocks until someone connects to my server. Is there a way, to be able to find the IP of the program/user who connects to my server?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
Try