Skip to content

UDP Broadcast - Local Network Broadcast #83

Open
@nbl1268

Description

@nbl1268

Hi there, looking for some guidance with sending UDP broadcast messages.

Have written a small program to send data via UDP to my local network; packets are very short (maybe 10 bytes of data).

The problem i am experiencing is that the local network broadcast (eg n.n.n.255) doesnt seem to be working, whereas 255.255.255.255 does work.

Here is extracts from my code to help explain what i am doing

// **** ETHERNET SETTING ****
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };
IPAddress ip(192, 168, 42, 111); // My network

//IPAddress ipB(192, 168, 42, 255); // doesnt work?? unsure why
IPAddress ipB(255, 255, 255, 255); // works
int portB = 42673; // broadcast UDP port

i have set a local Port so i know what port number the UDP messages are coming from
// Setup UDP Messaging
EthernetUDP udp;
unsigned int localPort = 2390;

i use this command/constructor to setup my arduino with the right local ip address
Ethernet.begin(mac, ip); // use specified IP

and this command to setup my UDP messaging
udp.begin(portB); // start UDP service

and this command to send the UDP message (with the result being stored in 'success')
success = udp.beginPacket(ipB,portB);

my network is 192.168.12.1/24 (or 255.255.255.0)

If i set the broadcast address to 255.255.255.255 then i receive the UDP packets on my PC from my arduino.

However, when i use the local broadcast address, eg 192.168.42.255 my network packet application (on my PC) doesnt receive any UDP packets from my arduino which is on ip address 192.168.42.111.
(have tried this on another network and have the same results.)

I have used a network packet monitoring application and can see my arduino sending ARP messages requesting the address for 192.168.42.255... i dont see any responses being sent back to the arduino either.

Can you help me understand why this is and what i need to look at to resolve this problem?
I'm thinking that if 255.255.255.255 works (UDP and DHCP) then 192.168.42.255 should also work.

Thanks
Neil

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions