Android 充当 wifi 服务器集线器?
我需要有一个 Android 设备作为 wifi 服务器/集线器来接受来自定制设备的原始数据所以首先,我需要 Android 设备作为一个 wifi 集线器来接受来自我的设备的原始数据。我该如何设置呢?我概述了 Tether 应用程序的代码,但我认为这行不通。我很高兴错了,但我不认为它能够广播 wifi。
其次,您对如何设置服务器有什么建议吗?我正在查看数据报通道,但我没有看到如何将它们绑定到端口,所以我正在考虑仅使用标准服务器,但我不确定如何将其连接到 wifi。
如果您对其中任何一个有任何指示,我们将不胜感激。
~伊顿
I need to have an android device act as a wifi server/hub that will accept raw data from custom built devices So first off, I need the android device to act as a wifi hub that can accept raw data from my devices. How do I do set that up? I overviewed the code to the tether application, but I don't think that will work. I'll be glad to be wrong, but I don't think It is able to broadcast wifi.
Secondly, do you have any suggestions on how to set up the server. I was looking at Datagram Channels but I didn't see anywhere how to bind them to a port so I'm considering just using a standard server, but I am not sure how to attach it the wifi.
If you have any pointers on either that would be appreciated.
~Aedon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,您有两个独立的问题,甚至不一定都必须通过手机来解决。
第一个是创建无线网络,使用电话或其他设备作为管理访问点(或进行临时无线)。系绳应用程序可能会对此有所帮助。
第二种是编写一个普通的基于套接字的网络服务器来完成你想做的事情。这可以本质上像在任何其他平台上一样在 java 中完成,或者本质上像任何其他基于套接字的 C 环境一样在本机库中完成 - 唯一的 android 独特部分将与活动生命周期相关,让您的代码启动并保持其运行,而不是为了支持前景中的其他内容而暂停或终止。
如果您的应用程序足够专业,您可能需要考虑对手机进行root。然后,您可以简单地在底层嵌入式 Linux 上用 C 语言编写服务器(即使没有 root 也可以这样做,尽管不鼓励这样做)并设置 OOM 杀手值来保护它,并且还可能自动启动它。这也可能有助于充当无线网络接入点 - 特别是如果不想实现从无线到 3g 的任何类似系绳的 NAT 功能,而未经授权的客户端可能会利用这些功能。
您可能还想权衡蓝牙与 WiFi 的优势,看看哪个更适合您的应用程序 - 不仅在技术上,而且在与手机通信的嵌入式设备的成本/复杂性方面。
You actually have two separate problems, which don't necessarily even both have to be solved with the phone.
The first is to create a wireless network, with either the phone or something else as the managing access point (or to do adhoc wireless). The tether application might be a help with that.
The second is to write an ordinary sockets-based network server to do whatever you want. This would be done either in java essentially as on any other platform, or in a native library essentially as any other sockets-based C environment - the only android unique parts will be activity lifecycle related, getting your code started and keeping it running rather than paused or killed in favor of something else in the foreground.
If your application is specialized enough, you might want to look into rooting the phone. You could then simply write the server in C on the underlying embedded linux (which you could do even without rooting, though it's discouraged) and set the OOM killer values to protect it, and potentially also start it automatically. This may also help with functioning as a wireless network access point - especially if would prefer to not to implement any tether-like NAT capablity from the wireless to the 3g which unauthorized clients might exploit.
You might also want to weigh the benefits of bluetooth vs. wifi and see which is a better fit for your application - not just technically, but in terms of cost/complexity of the embedded devices that will be talking to the phone.