如何在同一台计算机上用Java测试广播的udp数据包? [英] How to test broadcast udp packets in Java on the same machine?

查看:70
本文介绍了如何在同一台计算机上用Java测试广播的udp数据包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在机器上执行UDP广播数据包吗?我没有网络,只有便宜的linux机器.我想让一台服务器广播一个数据包,并在同一台计算机中的两个或多个客户端 接收它们.那可能吗?我使用什么IP?

Can I perform a UDP broadcast packets on my machine? I don't have a network, i just have my cheap linux box. I want to have a server broadcasting a packet and two or more clients in the same machine receiving them. Is that possible? What IP do I use?

@gravyface给了我希望,但我尝试了:1)服务器发送到127.255.255.255:54321,客户端监听0.0.0.0:54321.2)服务器发送到127.255.255.255:54321,客户端监听127.0.0.1:54321.3)服务器发送到127.255.255.255:54321,客户端监听127.255.255.255:54321.他们都没有工作!:(

@gravyface gave me hope but I tried: 1) server sending to 127.255.255.255:54321 and clients listenting to 0.0.0.0:54321. 2) server sending to 127.255.255.255:54321 and clients listening to 127.0.0.1:54321. 3) server sending to 127.255.255.255:54321 and clients listening to 127.255.255.255:54321. None of them worked! :(

OBS:我正在使用REUSE_ADDR和SO_BROADCAST选项.

OBS: I am using REUSE_ADDR and SO_BROADCAST options.

推荐答案

我能够确认127.255.255.255在Linux(Ubuntu)上可以运行,而在Mac(Snow Leopard)上不能运行.如果您知道如何在Mac上执行此操作,请告诉我.:)

I am able to confirm that 127.255.255.255 works on Linux (Ubuntu) and it does not work on Mac (Snow Leopard). If you ever find out how to do that on Mac let me know. :)

这篇关于如何在同一台计算机上用Java测试广播的udp数据包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆