haiyyu
haiyyu

Reputation: 2242

Do asynchronous sockets support sending messages to multiple clients at the same time?

Would this work?

Socket someUdpSocket = new Socket(...);
EndPoint[] aLotOfClients = { ... };

foreach (EndPoint ep in aLotOfClients)
{
    someUdpSocket.BeginSendTo(someData, 0, someData.Length, 
                              SocketFlags.None, ep,
                              new AsyncCallback(someMethod), ep);
}

I haven't been able to find an answer to this question.

Upvotes: 0

Views: 426

Answers (1)

Johannes Rudolph
Johannes Rudolph

Reputation: 35741

A socket can only send data to a single adress at a time, regardless if it is a synchronous or asynchronous socket.

However, you can send data to a set of special adresses (assuming you are working on the IP layer), called broadcast adressess. Theres two different flavors to send data to multiple clients at a time: Broadcasts and Multicast.

Broadcasts will be delivered to all clients connected to a network, although most networks put some restrictions on broadcasts so the network doesnt get flooded. The broadcast adress for you subnet is the last adress in that subnet as defined by the subnet mask. You can also broadcast into multiple subnets etc.

Multicasts are more like a chat room. Theres a set of multicast addresses reservede in IPV4 and you can join and levae a multicast group identified by an adress. When you send some data to the group, the network hardware will make sure to deliver a copy of your packet to all rceivers that joined the group.

I suggest you google around for multicast and broadcast (reading the rfc's isnt bad either), I hope I could get you started.

Upvotes: 1

Related Questions