Solved

Broadcasting from C++

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Internet bottleneck? 11 106
EIGRP  router failure 14 45
Can You Connect a Single Mode Fiber Run to a Multi-Mode Fiber Run 10 164
assessment of laptops/desktops for hardware refresh 6 67
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…
Before I go to far, let's explain HA (High Availability) and why you should consider it.  High availability is the mechanism used to provide redundancy to any service at the same site and appears as a single service to the users of that service.  As…
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…

813 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

10 Experts available now in Live!

Get 1:1 Help Now