-
August 20th, 2006, 11:53 AM
#1
broadcasting
Hi,
I was wondering how to broadcast packets onto a private network using winsock. I have used winsock before to set up a server/client connection but I do not understand how to have 1 machine broadcast it's data to all other machines at one go. Thanks
Amish
-
August 21st, 2006, 02:36 AM
#2
Re: broadcasting
Originally Posted by axr0284
I do not understand how to have 1 machine broadcast it's data to all other machines at one go
You have to broadcast ur data on 255.255.255.255 IP.
A special type of IP address is the limited broadcast address 255.255.255.255. A broadcast involves delivering a message from one sender to many recipients. Senders direct an IP broadcast to 255.255.255.255 to indicate all other nodes on the local network (LAN) should pick up that message. This broadcast is 'limited' in that it does not reach every node on the Internet, only nodes on the LAN
Following is the sample code for broadcasting.
Code:
char SBuf[512];
int SBufLength = 512;
SOCKET SenderSock;
SOCKADDR_IN RemoteAddr;
SenderSock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
RemoteAddr.sin_family = AF_INET;
RemoteAddr.sin_port = htons(5000);
RemoteAddr.sin_addr.s_addr = inet_addr(INADDR_BROADCAST); //INADDR_BROADCAST = "255.255.255.255"
sendto(SenderSock, SBuf, SBufLength, 0,
(SOCKADDR *)&RemoteAddr, sizeof(RemoteAddr));
A Person who is polite is given goodness and a person who is away from Politeness is away from Goodness.
NAUMAAN
-
August 21st, 2006, 02:13 PM
#3
Re: broadcasting
It's my understanding that both the sender socket and the recipient sockets must have SO_BROADCAST set with setsockopt, before any broadcasts take place.
Also, I think the sender must call connect(), even though connect() is ordinarily not needed for UDP, but I'm not certain of this either.
Mike
-
August 21st, 2006, 11:12 PM
#4
Re: broadcasting
What if I want multiple programs on the same computer to communicate via localhost ip address. Is that possible using UDP or TCP.
Amish
-
August 22nd, 2006, 05:15 AM
#5
Re: broadcasting
YEs Amish, u can have a many programs communicate with each other on the local host as u want, u can do that on UDP and TCP both ... which ever suites ur fancy ...
But i dont think that is a good technique, Can u tell us, what u want to do then we can tell u a good way of doing it ....
If you found my reply to be useful, please dont hesitate to rate it.
DO NOT kick the Axe if it doesnt fall on your foot.
Salman
-
August 22nd, 2006, 11:00 AM
#6
Re: broadcasting
Well I created an MANET emulator for a thesis. But it requires multiple computers with 1 real wireless transceiver connected to each computer. Since students might have to use this software, I would like to have the software be able to communicate with multiple versions of itself using tcp/ip. Then the students can test their program on one computer at home by themselves. When they are satisfied it works, they can port their programs to the lab and test it on real hardware devices. Makes sense?
Amish
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|