将服务器IP从wifi路由器提交到Android
我目前正在编写一个通过无线局域网连接到服务器的应用程序。
到目前为止,我已经将 IP 地址硬编码到应用程序中(运行完美),但是,下一个逻辑步骤是能够向应用程序发送服务器 IP 地址。
据我了解,路由器需要通过 255.255.255.255 广播 IP 地址 - 除此之外,我不知道该怎么做。
非常感谢任何和所有帮助,
编辑
好,所以我知道要使其正常工作,所有手机都必须与服务器位于同一网络上,这很好。
我需要做的是让电话在网络上广播,同时我的服务器监听。从那里,服务器向应用程序发送其 IP 地址,然后代码的其余部分可以继续。
有谁有教程或任何我可以遵循的东西来让双方工作吗?
I'm currently writing an app that's to connect to a server over a wireless lan.
So far, I've got the IP address hardcoded into the app (which works perfectly), however, the next logical step is to be able to send the app the server IP address.
From what I understand, the router needs to broadcast the IP address over 255.255.255.255 - apart from that, I have no idea what to do.
Any and all help is greatly appreciated
edit
ok, so I know to get this working, all phones have to be on the same network as the server, which is fine.
What I need to do is get the phone to broadcast on the network whilst my server listens. From there, the server sends the app its IP address, then the rest of the code can continue.
Does anyone have a tutorial or anything I can follow to get both sides working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个简单的解决方案是让您不必对服务器的 IP 或名称进行硬编码(假设它随着时间的推移而变化),您可以在网络上实现名称服务器并让 Android 设备调用本地 URL。
然后,您可以在本地网络上的网页标题中发布当前服务器的 IP 或名称。然后 Android 应用程序将使用此响应。
one simple solution for you not to hardcode the server's IP or name (let us say it changes over time), would be for you to implement a name server on your network and have the android device call a local URL.
you could then post the current server's IP or name in the header of a web page on your local network. this response would then be used by android app.