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

UDP broadcast example?

UDP broadcast

  • Please log in to reply
2 replies to this topic

#1 nlsa

nlsa

    Member

  • Members
  • PipPip
  • 11 posts

Posted 13 October 2015 - 12:32 PM

Could someone please point me to a working example of UDP broadcast with Netduino Plus 2 v. 4.2?  I find lots of online discussion from several years ago, mostly centered on bugs.  I'm just looking for how to broadcast UDP packets (receiving UDP is not necessary).  

Thank you -



#2 HSven1611

HSven1611

    Member

  • Members
  • PipPip
  • 14 posts

Posted 14 October 2015 - 11:44 AM

 Socket Socket { get; set; }

        public UdpClient(int port)
        {
            LocalPort = port;
            try
            {
                Socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);

                IPEndPoint broadcastEndPoint = new IPEndPoint(System.Net.IPAddress.Any, LocalPort);

                Socket.Bind(broadcastEndPoint);
            }
            catch
            {
                throw;
            }

            new Thread(new ThreadStart(threadStartTarget)).Start();
        }

  public int Send(byte[] data, EndPoint endPoint)
        {
            return Socket.SendTo(data, endPoint);
        }

This works for me and should give you a good starting point.

You might have to use the broadcast IPEndPoint to send broadcast.



#3 nlsa

nlsa

    Member

  • Members
  • PipPip
  • 11 posts

Posted 15 October 2015 - 03:56 PM

Great, thank you.







Also tagged with one or more of these keywords: UDP, broadcast

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.