Solved

Broadcasting from C++

Posted on 2009-07-08
3
879 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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Do you have a computer or other electronic gear that is attached to a rat nest of cables, or alternatively have your cables all bundled nice at neat?  If so then read this post to sidstep common pitfalls. When I was a student at DeVry University,…
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!
Viewers will learn how to properly install and use Secure Shell (SSH) to work on projects or homework remotely. Download Secure Shell: Follow basic installation instructions: Open Secure Shell and use "Quick Connect" to enter credentials includi…
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…

679 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