I already got the Netdiuno sending some random data. On the PC I'm running wireshark to see the packets.
Here's my sending code on the Netduino:
var serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); serverSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); serverSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true); var remoteEndPoint = new IPEndPoint(IPAddress.Any, 50505); serverSocket.Bind(remoteEndPoint); var data = new byte[]{1,2,3}; while (true) { serverSocket.Send(data); Thread.Sleep(1000); }
The only problem is: my desktop application does NOT receive those packets (while wireshark on the same machine does!).
Here's the receiving code on PC side:
private void Form1_Load(object sender, EventArgs e) { var broadcastAddress = new IPEndPoint(IPAddress.Any, 50505); this.udp = new UdpClient(); this.udp.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); this.udp.ExclusiveAddressUse = false; // only if you want to send/receive on same machine. this.udp.Client.Bind(broadcastAddress); this.udp.BeginReceive(new AsyncCallback(this.ReceiveCallback), null); } void ReceiveCallback(IAsyncResult result) { ... }
I checked the following things:
- Netduino is up, running and sending (packets arrive in wireshark on my PC)
- Netduino and PC are on the same subnet (255.255.255.0)
- Netduino and PC both use UDP on port 50505
- Desktop app is running and UDPClient has been successfully started
But my ReceiveCallback is never called...
Is there someone here who has successfully done this? Any advice? Thanks!