英文:
Unable to receive UDP packets in Go app on macOS
问题
我目前遇到了一个问题,我的Go应用程序在macOS上无法接收UDP数据包。我使用net包实现了一个基本的UDP监听器,但是尽管应用程序报告它正在监听指定的UDP端口,但当我将数据包发送到我的IP地址时,它却没有接收到任何数据包。
以下是部分代码(没有错误检查):
addr, err := net.ResolveUDPAddr("udp", ":1234")
conn, err := net.ListenUDP("udp", addr)
defer conn.Close()
buffer := make([]byte, 1024)
n, _, err := conn.ReadFromUDP(buffer)
fmt.Println("Packet Received!") //永远不会执行到这一行
我已经完成了以下操作:
- 验证了我的macOS机器上的防火墙已关闭。
- 使用nc命令行工具测试接收UDP数据包,在从运行Go应用程序的同一台机器发送数据包到本地主机(127.0.0.1)时成功。
- 但是,当我使用nc连接到计算机的自身IP地址时,Go应用程序没有接收到任何数据包。
- 此外,我尝试在同一台机器上实现一个Python UDP监听器,当发送到我的IP地址时,它成功接收到UDP数据包。
- 我还在其他计算机上进行了测试,一切正常。
现在我只需要它显示文本。
我认为它应该接收到UDP数据包,并在之后打印出文本。
英文:
I am currently facing an issue with my Go application on macOS where I am unable to receive UDP packets. I have implemented a basic UDP listener using the net package, but despite the application reporting that it is listening on the specified UDP port, it does not receive any packets when sending them to my IP address.
Here is part of the code (without error checking):
addr, err := net.ResolveUDPAddr("udp", ":1234")
conn, err := net.ListenUDP("udp", addr)
defer conn.Close()
buffer := make([]byte, 1024)
n, _, err := conn.ReadFromUDP(buffer)
fmt.Println("Packet Received!") //never reaches this line
I already did this:
- Verified that the firewall on my macOS machine is turned off.
- Tested receiving UDP packets using the nc command-line tool, which was successful when sending packets to localhost (127.0.0.1) from the same machine where the Go application is running.
- However, when I used nc to connect to the computer's own IP address from the same machine, the Go application did not receive any packets.
- Additionally, I tried implementing a Python UDP listener on the same machine, and it successfully received UDP packets when sent to my IP address.
- I also tested it on other computers and it worked fine.
Right now I just need it to show the text.
I think it should receive the udp packet, and print the text after.
答案1
得分: 0
问题与Podman相关。卸载Podman后,应用程序成功接收UDP数据包。
值得注意的是,我不确定Docker或其他容器化工具是否会出现相同的问题。然而,在我的特定情况下,移除Podman解决了这个问题。
英文:
The issue was related to Podman. Upon uninstalling it,the application started receiving UDP packets successfully.
It's worth noting that I'm unsure if the same problem occurs with Docker or other containerization tools. However, in my specific case, removing Podman resolved the issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论