简体   繁体   English

使用GDK在Google Glass上接收UDP数据

[英]receive UDP data on Google Glass with GDK

Any recommendations for receiving UDP data from an app running on Google Glass? 有关从Google Glass上运行的应用程序接收UDP数据的任何建议吗?

I need to integrate with an existing system. 我需要与现有系统集成。 This system does UDP broadcasts to the local subnet. 该系统对本地子网进行UDP广播。 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. Glass将位于同一子网上,并且Glass上运行的应用程序只需要在端口上侦听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. 看看文档,我看到网络相关的主题指向我更高级别的互操作,但我真的只是在寻找一个低级别的UDP接收套接字,并想知道在Glass上建议做什么。

Any suggestions? 有什么建议么?

According to GDK welcome page : 根据GDK欢迎页面

We designed the Glass platform to make the existing Android SDK just work on Glass. 我们设计了Glass平台,使现有的Android SDK可以在Glass上运行。 This lets you code in a familiar environment, but for a uniquely novel device. 这使您可以在熟悉的环境中进行编码,但是可以使用独特的新设备。

In addition, you can use all of the existing Android development tools, and your Glassware is even delivered as a standard Android package (APK). 此外,您可以使用所有现有的Android开发工具,甚至可以将您的Glassware作为标准Android软件包(APK)提供。

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 reference DatagramSocket参考

Nerdtron, did you make your glass UDP code work? Nerdtron,你是否让你的玻璃UDP代码工作?

I'm in very similar situation and trying to make my UDP code work as a GDK glassware app. 我的情况非常相似,并试图使我的UDP代码作为GDK玻璃器皿应用程序工作。

If you were successful, can you share how you made it work and also your codes? 如果您成功了,您能分享一下您的工作方式以及您的代码吗?

If not, what I have found so far are: 如果没有,我到目前为止发现的是:

  1. Networking part should run in a separate thread (not in the main thread). 网络部分应该在一个单独的线程中运行(不在主线程中)。 So knowing only about DatagramSocket/Packet won't help much at all. 所以只知道DatagramSocket / Packet就没什么用了。

  2. If the app needs to continuously run and receive data/packets, AsyncTask won't help. 如果应用程序需要连续运行并接收数据/数据包,AsyncTask将无济于事。 So stop using it. 所以停止使用它。 I wasted lots of time. 我浪费了很多时间。 We need to create a separate thread for continuously receiving data. 我们需要创建一个单独的线程来连续接收数据。 AsyncTask is for short or temporary tasks. AsyncTask用于短期或临时任务。

  3. GUI parts must not be manipulated in threads other than the main thread (the main thread is 'GUI' thread). 不得在主线程以外的线程中操作GUI部分(主线程是'GUI'线程)。 Any code which attempt to manipulate any GUI part (even texts) will generate error. 任何试图操纵任何GUI部分(甚至是文本)的代码都会产生错误。 So in order to change GUI, thread(s) receiving data via network/internet need(s) to use 'handler' (callback). 因此,为了改变GUI,通过网络/互联网接收数据的线程需要使用“处理程序”(回调)。

So continuously receiving data from network/internet and updating GUI in Android/Glass apps is not easy at all. 因此,不断从网络/互联网接收数据并在Android / Glass应用程序中更新GUI并非易事。 It requires clearly understanding how things work in Android/Glass apps regarding network and GUI. 它需要清楚地了解Android / Glass应用程序中有关网络和GUI的工作方式。

I made my code receive UDP packets and update texts in my Glass screen so far. 到目前为止,我让我的代码接收UDP数据包并更新我的Glass屏幕中的文本。 I'll try to share my code, findings, references, etc. later after I clean up my code and make sure it works somewhat correctly. 在我清理完代码并确保其工作正常后,我会尝试分享我的代码,调查结果,参考资料等。

Let me know if you have any questions. 如果您有任何疑问,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM