ezzakrem
ezzakrem

Reputation: 399

Is it possible to receive UDP datagrams from two different sources?

I'm using VC++ 2010 and Windows 7.

I have two UDP sources and only one receiver. Suppose source1 sends : 1, 3 , 5 and source2 sends 2, 4, 6. I want to receive 1,2,3,4,5,6 in the same function (digit order doesn't matter). Until now, I made 2 sockets listening on 2 different ports to receive data and then combine them.

How can I use a single socket instance to receive UDP traffic from multiple sources?

Upvotes: 0

Views: 838

Answers (1)

Maksim Skurydzin
Maksim Skurydzin

Reputation: 10541

On a receiver side create a single socket and bind it to some port. Then make both senders specify this port in the destination address calling sendto. This should do the trick.

There are several things you should remember working with UDP. The order in which the datagrams arrive is not specified. You won't know if any of the datagrams is not delivered either. Besides, you might even get duplicate datagrams several times.

Upvotes: 4

Related Questions