UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » Networking
  • » UDP broadcast packet receive by two programs on the same host?

#1 2005-07-14 06:45 PM

jfriesne
Administrator
From: California
Registered: 2005-07-06
Posts: 348
Website

Re: UDP broadcast packet receive by two programs on the same host?

Can someone tell me if it is possible for two programs running on the same computer to both receive the same broadcast-UDP packet?  It seems that it is not possible, since you can't have two programs bind to the same UDP port -- but that would be unfortunate, since it breaks the broadcast model for the multiple-receivers-on-the-same-computer case.  So perhaps there is some sneaky way to do it?  (I understand that multicast supports this, but I don't think multicast will be a viable option for my application)

Offline

#2 2005-07-14 07:20 PM

jfriesne
Administrator
From: California
Registered: 2005-07-06
Posts: 348
Website

Re: UDP broadcast packet receive by two programs on the same host?

And now, to answer my own question... here is code that appears to do the trick, at least under OS/X, Windows XP, and Linux.  Dunno how portable it is to other OS's.

int one = 1;
setsockopt(udpSock, SOL_SOCKET, SO_REUSEADDR, (const char *) &one, sizeof(one));
#ifdef __APPLE__
setsockopt(udpSock, SOL_SOCKET, SO_REUSEPORT, (const char *) &one, sizeof(one));
#endif

Offline

#3 2012-08-26 06:01 PM

ChrisApotek
Guest

Re: UDP broadcast packet receive by two programs on the same host?

  • Index
  • » Networking
  • » UDP broadcast packet receive by two programs on the same host?

Board footer

Powered by FluxBB