I'd like to know how to implement a discovery function in a LAN P2P Network. I don't want to use the .NET 3.5 P2P library,i want to design it myself.For the moment when a user presses Connect button, he sends a broadcast message in the lan, informing the other peers that he is available.The other peers on the receiving Thread identify that message and by their will can establish a connection. For example: Machine 1 with IP 192.168.0.101 presses connect and sends a message "Command.Connect" at "255.255.255.255" for broadcast Machine 2 with IP 192.168.0.102 waits on a Thread for Udp messages and identifies that peer with IP 192.168.0.102 When a user presses Disconnect another command "Command.Disconnect" is sent in the same manner. Can you tell me please if it is a good idea for discovering peers in a LAN?
If you are designing it for simple LAN only then you can also consider using IP-Multicast instead of UDP broadcast. Using IP-Multicast you new peer will only send message to interested peers only but in case of broadcast your message will be sent to all computers even if they are not running your chat program. However there are pros and cons for both options and depends upon your requirement and future plans for your application.
Secondly if it is possible for you to have a server in the system then it can be more fine-tuned. You can keep your chat messaging on peer-to-peer model but when some peer comes online, then it can register with a dedicated server and ask the server to provide list of other registered peers and then you can directly interact with other peers. This will also be helpful if you intend to add features like authentication etc.