C
Join ServerC#
help
UDP Multicast does not work as expected [Answered]
Ccap5lut10/25/2022
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
but that is not the case, only the writer and reader 1 is spitting out stuff.
what am I doing wrong?
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
but that is not the case, only the writer and reader 1 is spitting out stuff.
what am I doing wrong?
CCisien10/25/2022
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
XWYBxianzai wo you bingqiling10/25/2022
it is already using task.whenall
CCisien10/25/2022
Thats not necessarily going to start all three tasks
XWYBxianzai wo you bingqiling10/25/2022
in my case with multiple serialports it does
CCisien10/25/2022
Async/await is intended for i/o
CCisien10/25/2022
This code isnt i/o
Ccap5lut10/25/2022
just added some more logs, seems the 2nd reader is stuck on
socket.Bind(new IPEndPoint(IPAddress.Any, MulticastPort));
Ccap5lut10/25/2022
its throwing
System.Net.Sockets.SocketException (10048)
Ccap5lut10/25/2022
but now i still dont understand how i would make that work
XWYBxianzai wo you bingqiling10/25/2022
Ccap5lut10/25/2022
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
did the job, thanks for ur help!AAccord10/25/2022
✅ This post has been marked as answered!