Find program running on other machines on the LAN

Ehsanit

Well-known member
Joined
Feb 23, 2011
Messages
80
Programming Experience
1-3
GENERAL TASK: I'm working on a simple LAN messenger program for my family. I sorted the basic GUI out quite easily and will build on the additional bells and whistles once the main communication system is in place. I've also successfully set up the asynchronous TCP listener and sender to carry messages, and by manually inputting the IP of the destination have persuaded the message to traverse the radio waves and display on the remote computer.

SPECIFIC TASK: However I have thus far failed to find a way to identify other programs on the network running the software as valid targets for communication. Obviously most of the IPs in the 192.168 range are not allocated, and of those that are they are as prone to be a router or computer not running the software as they are to be a valid destination.

PLAN: My thinking has been the following, but if there are better ways to do this I am of course open to suggestions.

When a client wants to refresh its list it sends out a UDP broadcast (or possibly multicast) with its own details and an "initial" value set.
All clients bind to the UDP broadcast address.
When a client gets a datagram it updates its own records with that IP-name combination.
If the initial byte is set it then sends out its own details on broadcast/multicast (without the initial byte, or the cycle would just explode.)

PROBLEM: Unfortunately in attempting to implement this I'm getting a JIT error on all test machines except (strangely) my development computer
************** Exception Text **************
System.Net.Sockets.SocketException (0x80004005): The requested address is not valid in its context
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at Ehsanit_LAN_Messenger.ELM.PrepareHailerListen()
at Ehsanit_LAN_Messenger.ELM.Program_Load(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)

The UDP send works as expected and carries the IP and name properly to the development machine, but the receive on all other computers does not execute after this error. I can provide relevant code as requested.
 
I finally managed, after ditching my code and starting afresh, to get this fixed.
I did have many misconceptions about how networking worked in general, and consequently had a number of mistakes. It's amazing how much one learns over 18 months of reading things.
The specific problem causing the error, however, was that I sent to the 255.255.255.255 broadcast address and specified broadcast as the address to receive too. Instead I had to specify ANY as the address to listen to. Just in case anyone runs into the same problem.
 
Back
Top