Solved

Broadcasting from C++

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

A few months ago I attended the Rocky Mountain IPv6 Summit which was a two-day educational event; it was the 3rd annual conference held here in Denver, Colorado that was held at the Hyatt Regency Denver at the Colorado Convention Center. It was an e…
I know for anybody starting from Beginner to Expert in Networking knows what OSI model. But this tutorial is for freshers or those who are new to networking world. Why I am putting OSI in such simple and compact manner is because it enables you to k…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now