简体   繁体   English

在Google Compute Engine上接收UDP数据包

[英]Receive UDP Packets on Google Compute Engine

my task is to receive UDP packets on an Google Compute Engine. 我的任务是在Google Compute Engine上接收UDP数据包。 Given is the port, which is 300 and I already have a simple Java program which can handle these UDP packets. 给定的端口是300,我已经有一个简单的Java程序可以处理这些UDP数据包。

My problem now. 我的问题了。 Get the UDP packets to my Java program. 获取UDP数据包到我的Java程序。

For that I don't know how to do this. 为此,我不知道该怎么做。 What I have tried so far ist to let the Java program direct listen to the port, which didn't work. 到目前为止,我一直在尝试让Java程序直接监听端口,但该端口无效。 I suspect the traffic from outside the GCE must be routed to the inside? 我怀疑来自GCE外部的流量必须路由到内部吗?

First make sure you've added a firewall rule on your GCE VM instance's network which allows incoming traffic for UDP protocol on port 300. You can do this by going to the Developers Console, select your project, then Compute-> Compute Engine-> Networks, click on the right network and verify firewall rules (and tags as well if you used them). 首先,请确保已在GCE VM实例的网络上添加了防火墙规则,该规则允许端口300上的UDP协议传入流量。您可以通过以下步骤进行操作:转到开发者控制台,选择您的项目,然后选择Compute-> Compute Engine->网络,单击正确的网络并验证防火墙规则(以及使用的标签,以及标签)。 If the rule is not added, then add a rule for the traffic. 如果未添加规则,则为流量添加规则。

"gcloud" is a command-line tool which you can use it to list and verify your firewall rules as well [1]: “ gcloud”是一个命令行工具,您也可以使用它来列出和验证您的防火墙规则[1]:
$ gcloud compute firewall-rules list $ gcloud计算防火墙规则列表

If the firewall rules are good, then use a simple troubleshooting tool like netcat to test if traffic is being forwarded to your VM instance. 如果防火墙规则很好,请使用简单的故障排除工具(如netcat)来测试是否将流量转发到您的VM实例。

1. Listing Google Compute Engine firewall rules 1.列出Google Compute Engine防火墙规则

I recommend not using Java to process UDP. 我建议不要使用Java处理UDP。 I experienced inexplicable short periods where all UDP traffic arriving was being lost. 我经历了莫名其妙的短时间,所有到达的UDP流量都丢失了。 This was caused by garbage collection. 这是由垃圾收集引起的。

The architecture that works for me is to use a GCE VM with a C++ app receiving UDP data, then using libCURL, convert the data to HTTP and dispatch it to Google App Engine for processing. 对我有用的体系结构是将GCE VM与C ++应用程序一起使用,以接收UDP数据,然后使用libCURL,将数据转换为HTTP,然后将其分发给Google App Engine进行处理。 To make the UDP receiver scalable and tolerant, use network balancing and multiple VMs listening for UDP. 为了使UDP接收器具有可伸缩性和容错性,请使用网络平衡和侦听UDP的多个VM。

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

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