Search code examples
c#.nettcpudpmesh-network

Determining the IP address of neighbors in a wireless mesh


I am attempting to create a program for a wireless mesh (adhoc in all but name). Most of the network will deal with TCP messaging but to determine all neighbor IPs (as they will be unknown on startup), I choose to use UDP Broadcast for the initial discovery messages.

I have two problems currently. First, the UDP Broadcast is only being received by the sender and none of its neighbors; second, as the receiving socket can not accept the sender's socket (due to the message being a datagram), I am not able to recover an IP address.

I am in need of a methodology that would allow this to work.


Solution

  • You're supposed to get the source address along with the datagram via e.g. recvfrom. Here's the .NET version. You also have to set a socket option to send broadcast datagrams.

    See also this question: Broadcasting UDP thru all network cards