UDP messages lost

Hello,

I have made two programs, one to broadcast UDP messages containing a string of text and one to receive those messages and display the string. Currently I got to the point where it works if I run both on the same system, but I was using sockets because I want to receive the messages on another computer. Unfortunately if I move my client program to another computer it suddenly stops receiving the messages.
I think this is because the Windows 7 computer with the sender does not allow the messages to go to the network and/or the computer with the client (I tried Windows 7 and Windows XP) does not allow receiving the messages.

My sender program connects to its own IP-addres: 169.254.76.223 and should send on port 11222 and the windows firewall for both private and public networks is disabled. The sender currently has an infinite loop, so it will keep sending.
1
2
3
4
		SendingSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
			BroadcastAddr.sin_family = AF_INET;
			BroadcastAddr.sin_port = htons(11222);
			BroadcastAddr.sin_addr.s_addr = inet_addr("169.254.76.223");


My receiver connects to port 11222 and should accept messages from any IP-address. Also on this computer, the windows firewall for both private and public networks is disabled. The receiver currently has an infinite loop, so it will keep listening for new messages and if something goes wrong it should output an error message and try to start listening again.
The client computers have IP: 169.254.185.53 and 169.254.76.254. Also if I try to ping the sender computer from a receiver computer I get the response within 1ms.
1
2
3
4
		ReceivingSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
			ReceiverAddr.sin_family = AF_INET;
			ReceiverAddr.sin_port = htons(11222);                // The port where we listen for messages
			ReceiverAddr.sin_addr.s_addr = htonl(INADDR_ANY);   // From all interface (0.0.0.0) 


Does anyone have an idea why the messages don't get received on another computer on the network?
Does anyone have any suggestions for things that I might try to get this setup to work over the network?
My sender program connects to its own IP-addres

Instead of your own IP-address shouldn't you use the IP-address that you want to send to?
I was (mistakenly) thinking that I should tell it somewhere which network to use for sending the message and that it would broadcast the message. But you are right, it should have been the receiver address. When I changed that the message came through.

You have just made my weekend a lot nicer. Thank you very much.

I would however prefer to broadcast to every computer in that part of the network. With Google I found remarks about sending to IP 127.255.255.255, but I also found that that does not always work. When I tried it, it did not work that easily.

Is there still a way to broadcast to every computer that is connected to the same switch/router or has this option been removed?
Last edited on
I just found out how to do the broadcasting too.

For future readers:
It depends on the subnet, my IP 169.254.185.53 has a subnet mask of 255.255.0.0.
To broadcast a message to every computer in the same network (you can't get past a router) you have to use to replace every 255 in the subnet mask with the numbers of your own IP-address and every 0 in the subnet mask should be replaced by a 255.

So in my case (IP-address 169.254.185.53, and subnet mask of 255.255.0.0), I should send an UDP message to 169.254.255.255 if I want to broadcast it to every computer.
Topic archived. No new replies allowed.