收到谷歌玻璃与GDK UDP数据玻璃、数据、GDK、UDP

2023-09-07 22:38:55 作者:劫难逃.

从上谷歌玻璃?

我需要与现有系统集成。该系统确实UDP广播到本地子网。玻璃会在同一个子网中,在玻璃上运行该应用程序只需要一个端口的UDP数据包监听,然后显示其中包含的用户信息。

I need to integrate with an existing system. This system does UDP broadcasts to the local subnet. The Glass will be on the same subnet and the app running on the Glass just needs to listen on a port for UDP packets and then display information contained in them to the user.

我整合与现有的系统,我没有自由,改变了这一点,所以希望只接收UDP(而不是使用其他的,也许是更好的,更高层次的框架)。

I'm integrating with an existing system which I don't have the freedom to change at this point and so want to just receive UDP (as opposed to using other, perhaps better, higher level frameworks).

环顾文档我看到网络相关的主题指向我更高级别的工具和互操作的,但我真的只是寻找一个低级别的UDP接收插座,想知道什么是建议在玻璃这样做。

Looking around the docs I see network related topics pointing me to higher level stuff for interoperating, but I'm really just looking for a low level UDP receiving socket and wondering what would be recommended for doing this on Glass.

有什么建议?

推荐答案

根据 GDK欢迎页面:

我们设计了玻璃平台,使现有的Andr​​oid SDK中只是工作的玻璃。这使您可以code在熟悉的环境,但对于一个独特新颖的设备。

We designed the Glass platform to make the existing Android SDK just work on Glass. This lets you code in a familiar environment, but for a uniquely novel device.

另外,你可以使用所有现有的Andr​​oid开发工具,和你的玻璃器皿甚至交付标准的Andr​​oid包(APK)。

In addition, you can use all of the existing Android development tools, and your Glassware is even delivered as a standard Android package (APK).

所以,presumably你应该能够做一些沿(未经测试)的行:

So, presumably you should be able to do something along the lines of (untested):

byte[] buf = new byte[1024];
DatagramSocket socket = new DatagramSocket(port);
DatagramPacket packet = new DatagramPacket(buf, buf.length);
socket.receive(packet);

DatagramSocket的参考