Sending packets to 255.255.255.255 by Java DatagramSocket fails

前端 未结 4 1484
傲寒
傲寒 2020-12-11 01:55

I\'m programming a networking program in java , and I want to send some Packets to 255.255.255.255, but it fails , even when I send them to 192.168.1.255, which according to

4条回答
  •  情书的邮戳
    2020-12-11 02:18

    While using broadcasting you need to enable it

    socket.setBroadcast(true);
    

    Another thing is that you have to make sure that your router is configured right if the two computers are in two different nets. Broadcasts are usually by default not routed. Further if you have a router having a wirless interface and a wired interface these broadcasts may not work either if broadcasts are not enabled(There may be hardware which forward broadcasts between those two interfaces by default).

提交回复
热议问题