I am trying to receive UDP packets on the raspberry pi. I have created a simple java program to connect the network. (I have all relevant code below)
String myNetworkAddress = "10.0.0.11";
String myBroadcastAddress = "10.255.255.255";
// Setup network connection
try {
InetAddress nicAddress = InetAddress.getByName(myNetworkAddress);
InetAddress baddr = InetAddress.getByName(myBroadcastAddress);
dmx = new ArtNet(nicAddress, baddr);
udpsocket = new DatagramSocket(null);
udpsocket.setReuseAddress(true);
udpsocket.bind(new InetSocketAddress(nicAddress, dmx.getPort()));
udpsocket.setBroadcast(true);
udpsocket.setSoTimeout(1000);
System.out.println("Opened socket " + udpsocket.getLocalAddress() + ":" + udpsocket.getLocalPort());
} catch (Exception e) {
System.out.println("can't open socket " + e);
}
while (true) {
if (udpsocket != null) {
if (dmx.readPacket(udpsocket)) {
i = dmx.getPacket();
// read packet and process
}
}
}
I am not able to receive anything from the broadcast, on a raspberry pi. But when I run this code on another computer, I am able to receive packets from the broadcast. This leaves me to believe that java is not given access to creating a socket, binding the port and that it is not the code but a security measure on the raspberry pi.
Things that I have tried:
Ifconfig:
eth0 Link encap:Ethernet HWaddr b8:27:eb:11:11:11
inet addr:192.168.1.48 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:351 errors:0 dropped:0 overruns:0 frame:0
TX packets:376 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:25333 (24.7 KiB) TX bytes:77137 (75.3 KiB)
dhclient.conf (Used when no router/dhcp server is available, connection is made between a computer and raspberry pi with a static ip):
timeout 10;
lease {
interface "eth0";
fixed-address 10.0.0.10;
option broadcast-address 10.255.255.255;
option subnet-mask 255.0.0.0;
option host-name "node.local";
renew 2 2022/1/1 00:00:01;
rebind 2 2022/1/1 00:00:01;
expire 2 2022/1/1 00:00:01;
}
With no luck. any advice or help would be greatly appreciated.
By Binding on the NicAddress, it only accepts incoming packets from the network address. Binding to 0.0.0.0 Will allow incoming pacts from the broadcast IP as well as other IP addresses
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.