Solved

Broadcasting from C++

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

Industry Leaders: 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

Understanding FTPS File transfer is a common requirement in most Enterprises. While there are numerous ways to get a file from Point A to Point B over a network, perhaps the most common method still in use is FTP – File Transfer Protocol. FTP is …
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

689 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