Solved

Broadcasting from C++

Posted on 2009-07-08
3
881 Views
Last Modified: 2013-11-29
Dear All,

Would you know, please, how I can listen, from C++, to UDP broadcasts by multiple clients on the same machine.
One client per machine doesn't appear to be a problem for the given port.
But multiple clients cannot use the same port with the bind call.
All the TCP listenning, connecting, accepting works fine for me but I don't appear to know enough about UDP.

Is is possible at all to broadcast single message to multiple clients on one machine without using some kind of intermediary service?

Best wishes,
Milan

0
Comment
Question by:milan_novkovic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Accepted Solution

by:
JIEXA earned 250 total points
ID: 24810665
Broadcasting and multicasting sends packets to different IPs with the same port number. So, if you need this way, you can define multiple IP addresses for the same NIC card, and to define that every client listens to one IP exactly of the defined ones.

But I'd do it another way, if the architecture is: multiple clients and server on a single host. I'd organize shared memory by a server (which is attachable by clients), and put there a semaphore (not a kernel one) or another multi-locking item that can reside in specified memory. Server locks the item for every client connected, and unlocks it at once for all clients. Clients wait for unlock...
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 250 total points
ID: 24812749
>>>> But multiple clients cannot use the same port with the bind call.
clients do not call bind. It is a server function. It associates a name to an UDP or TCP socket.

For UDP client read you normally would create a socket, then call connect (what not really is a connection but filters messages to only get those of the server), then call select with timeout to wait for messages you could read with a recv. Or you set the socket to non-blocking and read from socket until the EWOULDBLOCK error has vanished.

0
 

Author Closing Comment

by:milan_novkovic
ID: 31601103
Thanks Guys,

I learnt more about connect with connectionless sockets from itsmeandnobodyelse yet will do as JIEXA suggested as I didn't clarify that I can have randomly changing number of servers on a complex, big network (doing very high volume, very high number of clients messaging project).

Shared memory idea was on the table all along but i hoped that there was something in the broad/multicasting business that can help.

Best wishes,
Milan
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
Configuring network clients can be a chore, especially if there are a large number of them or a lot of itinerant users.  DHCP dynamically manages this process, much to the relief of users and administrators alike!
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question