willardf / Hazel-Networking

Hazel Networking is a low level networking library for C# providing connection-oriented, message-based communication via RUDP.
MIT License
385 stars 60 forks source link

Send broadcast to all network interfaces #14

Closed Elsensee closed 1 year ago

Elsensee commented 3 years ago

I noticed, when fiddling around with Among Us, that I wasn't able to host a local game on my computer. In Wireshark it turned out, that in fact no broadcast was sent out. Instead they were sent on the virtual adapter and only there. After research, I found out, that you must bind the socket to every network interface, if you want to send it out on more than one.

I decided to fix it myself. (I was already in the Hazel code for some time, due to some refactoring around IPv6 and also enabling multicast support, so I stashed that work) To save on allocations and not introduce new dependencies I created a new struct inside of UdpBroadcaster, which holds the Socket and Endpoint (instead of using System.Tuple (which is a reference type), System.ValueType (which is a nuget package)).

I verified that this is indeed working and will send a broadcast on every network interface and not just the first that it finds in the routing table.

Elsensee commented 1 year ago

@willardf Haha, it's alrighty! I'm happy I was able to help. :) Maybe I have some work on IPv6 support somewhere on my notebook that I could share if you like, though I haven't looked into this codebase for quite some time as you could imagine. ;)