Socket UDP Broadcast

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0

Presently, the app has a Listen socket on a unique port for data. Every app on the network knows what port to connect to via the IP of the target system.

I need to understand how to setup a UDP Listen socket on port x1000.

Should I just setup the socket like I do for a normal Listening socket but defined as UDP.
And then process the incoming Accept if a broadcast "connect" is detected.
Or do I just create a UDP socket without any specific target address using some special code?

If the app is to also to be able to broadcast out, the socket/port needs to be shared.
Broadcasts are intended to go out on x1000.

Will sharing the inbound/outboad be a problem. With broadcasts is there an actual socket connection setup between systems or just a socket is just pushing data out to any other socket that is listening on the defined common port.

Using MFC but any explanation will be able to be usable/helpful.

Hopefully my problem is described clear enough that some socket masters can assist.
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
UDP is completely connectionless. So to receive data on port A, all you need to do is to create and bind a UDP socket to port A, then get data from it as you would from a connected TCP socket (using select(), recv(), recvfrom() etc.). You can send data from the same socket (i.e. from the same port) using sendto().
 

bsobel

Moderator Emeritus<br>Elite Member
Dec 9, 2001
13,346
0
0
With broadcasts is there an actual socket connection setup between systems or just a socket is just pushing data out to any other socket that is listening on the defined common port.

With broadcasting, you send to the broadcast address. From your point of view, its just like sending to any other specific IP, except any receivers will know to treat that datagram as if you sent it directly to them as well. So yes, you broadcast to the same port as you would do the directed send.

 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Thanks both of you.

My concern was that I needed to setup a Listening/Accept which would have caused some conflicts.


Not having to do so simplifies the equation greatly.