计算机上同一端口上的 UDP 套接字通信

发布于 2024-09-24 16:44:11 字数 195 浏览 1 评论 0原文

我在同一台计算机上有两个程序,使用 udp 套接字进行通信。当程序 A 运行时,我想提取一些信息到程序 B。使用 SO_REUSEADDR 套接字选项,我可以将 2 个程序绑定到同一端口。然而,当程序A发送消息时,程序A本身而不是B接收到消息并显示在控制台中。我想知道为什么消息没有定向到B,是否是因为同一个端口上绑定了2个程序而udp不知道将消息定向到哪个程序? 提前致谢。

I have 2 programs on the same computer, communicating using udp socket. While program A running, I want to extract some information to program B. Using the SO_REUSEADDR socket option, I am able to bind 2 programs to the same port. However, when program A sent a message, program A itself, instead of B, received the message and display in console. I am wondering why the message isn't directed to B, is it because of 2 programs bound on the same port and the udp doesn't know which program to direct the message?
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卷耳 2024-10-01 16:44:11

将两个程序绑定到同一个套接字是非常糟糕的主意。使用程序 B 作为“代理”(通过它传输程序 A 的所有内容),然后您就可以读取通信。

It is VERY bad idea to bind two programs to the same socket. Use Program B as a 'proxy' (tunnel everything from program A through it), and then you can read the communication.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文