C
C#3y ago
cap5lut

UDP Multicast does not work as expected [Answered]

I am starting to play around with UDP for some IPC stuff and wrote a simple UDP Multicast application just to have a playground to advance from, but sadly its not going as expected. First of all: here is the code of the small program https://gist.github.com/cap5lut/ce3bfda6a0997b647a67a20d78d9e189 My expectation was that the writer sends the data and both readers would receive the data, resulting in an output like
writer: sending 5
reader 1: read 5
reader 2: read 5
writer: sending 5
reader 1: read 5
reader 2: read 5
but that is not the case, only the writer and reader 1 is spitting out stuff. what am I doing wrong?
Gist
UDP Multicast Test.cs
GitHub Gist: instantly share code, notes, and snippets.
9 Replies
Cisien
Cisien3y ago
Its possible the 2nd reader isnt being scheduled. Async/await isnt necessarily going to provide concurrency. Try using threads or manually created long running tasks
realivanjxツ
realivanjxツ3y ago
it is already using task.whenall
Cisien
Cisien3y ago
Thats not necessarily going to start all three tasks
realivanjxツ
realivanjxツ3y ago
in my case with multiple serialports it does
Cisien
Cisien3y ago
Async/await is intended for i/o This code isnt i/o
cap5lut
cap5lutOP3y ago
just added some more logs, seems the 2nd reader is stuck on socket.Bind(new IPEndPoint(IPAddress.Any, MulticastPort)); its throwing System.Net.Sockets.SocketException (10048) but now i still dont understand how i would make that work
cap5lut
cap5lutOP3y ago
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); did the job, thanks for ur help!
Accord
Accord3y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server