ANDROID - 显示运行相同应用程序的手机的 IP 地址列表

发布于 2024-11-02 18:03:21 字数 340 浏览 0 评论 0原文

我正在开发一个多线程客户端-服务器Android应用程序,其中客户端和服务器都是Android手机(服务器不在中心位置)并且位于同一网络中,在一个路由器的控制下。

服务器将首先启动应用程序。当客户端启动应用程序时,他们应该自动获取服务器电话的IP地址,这样当他们点击该地址时,就可以连接到服务器。

现在,我做了一个规定,当应用程序开始运行时,服务器电话在屏幕上显示其IP地址。当客户端启动应用程序时,会提供一个文本字段,用户可以在其中手动输入服务器的 IP 地址并连接到它。

谁能告诉我如何让服务器的 IP 地址自动显示在客户端电话上?我需要一个中央数据库或类似的东西吗?我是 Android 编程新手,对此一无所知。

I am developing a multi threaded client-server Android app in which both clients and the server are android phones( the server is not centrally located) and are located in the same network, under the control of one single router.

The server will start the application first. When the clients starts the app, they should get the IP address of the server phone automatically, so that when they click the address, they can be connected to the server.

Right now, I have made a provision that the server phone displays its IP address on the screen when the app starts running. When a client starts the app, it is provided with a text field in which the user can manually type the server's IP address and get connected to it.

Can anyone give me any pointers on how I can get the server's IP address to be displayed on the client phone automatically? Do I need a central database or something like that? I am new to android programming and don't really have any idea about this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

棒棒糖 2024-11-09 18:03:22

看看这是否有用:Android IP address with java

See if this is useful: Android IP address with java

眸中客 2024-11-09 18:03:22

您可能需要考虑实施 UPnP 解决方案。请参阅此通用即插即用作为入门,然后检查末尾的链接以获取相关文档/参考。

UPnP 不要求设备明确了解其他设备的网络详细信息,而是使用发现协议 (SSDP) 相互定位。

You might want to think about implementing a UPnP solution. See this Universal Plug and Play as a starter then check the links at the end for relevant docs/references.

UPnP doesn't require devices to explicitly know the network details of other devices and instead they locate each other using a discovery protocol (SSDP).

深爱成瘾 2024-11-09 18:03:22

一种解决方案是循环 ping 本地 IP 范围。设置一个小的超时时间。如果您在单独的线程中运行它会更好。如果您收到 ping 响应,则意味着服务器可用。

One solution is to ping local IP range in a loop. Put a small timeout duration. It would be better if you run it in separate threads. If you get ping response, this would mean the server is available.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文