Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

NetDuino Plus not Receiving UDP Broadcast Packets


  • Please log in to reply
4 replies to this topic

#1 Homey

Homey

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 03 May 2012 - 05:55 PM

All I need some help. I have a simple socket app that sends a UDP broadcast packet to my local network on a specific port. The NetDuinoPlus socket.receivefrom method doesnt get fired. However if i run as Emulator it works perfectly. SolutionReleaseInfo.solutionVersion: 4.1.0.6 (firmware version) Can someone tell me what i have to do to get my NetDuinoPlus to receive a UDP Broadcast packet? My receive code is simply: Socket sock = new Socket(AddressFamily.InterNetwork,SocketType.Dgram, ProtocolType.Udp); IPEndPoint iep = new IPEndPoint(IPAddress.Any, 9050); sock.Bind(iep); EndPoint ep = (EndPoint)iep; byte[] data = new byte[64]; int recv = sock.ReceiveFrom(data, ref ep); There has to be something wrong here for a "Net" Duino to not receive a simple UDP Broadcast.

#2 Valkyrie-MT

Valkyrie-MT

    Advanced Member

  • Members
  • PipPipPip
  • 315 posts
  • LocationIndiana, USA

Posted 04 May 2012 - 12:55 AM

... sends a UDP broadcast packet to my local network ...
SolutionReleaseInfo.solutionVersion: 4.1.0.6 (firmware version)


UDP Broadcast was broken on all firmware versions prior to 4.2 RC3.

Note: the jury is still out on UDP Multicast though, even with the 4.2 RC4.

-Valkyrie-MT

#3 Homey

Homey

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 04 May 2012 - 05:48 PM

UDP Broadcast was broken on all firmware versions prior to 4.2 RC3.

Note: the jury is still out on UDP Multicast though, even with the 4.2 RC4.

-Valkyrie-MT



so i should at least try to update the firmware to 4.2 RC4? If so, where do i get it?

many thanks for a response!

#4 emg

emg

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 04 May 2012 - 07:58 PM

4.2 RC4

#5 Immo

Immo

    New Member

  • Members
  • Pip
  • 1 posts

Posted 05 May 2012 - 02:17 PM

Hi Homey,

following code I use on ND+ to receive UDP Broadcast packets
from iPhone and it works fine here with 4.1 and 4.2:

private void threadStartTarget()
        {
            _socket = new Socket(AddressFamily.InterNetwork,
                SocketType.Dgram, ProtocolType.Udp);
            try
            {
                IPEndPoint broadcastEndPoint = new IPEndPoint(
                    System.Net.IPAddress.Any, LocalPort);
                
                _socket.SetSocketOption(SocketOptionLevel.Socket,
                    SocketOptionName.ReuseAddress, true);
                if (Broadcast)
                    _socket.SetSocketOption(SocketOptionLevel.Socket,
                        SocketOptionName.Broadcast, true);

                _socket.Bind(broadcastEndPoint);

                while (true)
                {
                    EndPoint remoteEndPoint = new IPEndPoint(
                        System.Net.IPAddress.Any, 0);

                    int availableBytes = _socket.Available;
                    if (availableBytes > 0)
                    {
                        byte[] receiveBuffer = new byte[availableBytes];
                        _socket.ReceiveFrom(receiveBuffer, ref remoteEndPoint);

                        if (DataReceived != null)
                            DataReceived(this,
                                new DataReceivedEventArgs(
                                    receiveBuffer, remoteEndPoint));
                    }
                    // This is recommends in thread loops to help prevent lock-ups
                    Thread.Sleep(10);
                }
            }
            catch (Exception e)
            {
                // catch all exceptions
                Debug.Print(e.ToString());
            }
            finally
            {
                doDispose();
                if (SocketDone != null)
                    SocketDone(this, EventArgs.Empty);

                Debug.Print("UDP server thread finished.");
            }
        }
HTH, Immo




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.