I'm curious about how the "Open to LAN" feature in Minecraft lets players see host connections right away when it's activated. I've tried finding tutorials, but aside from one confusing Godot tutorial that didn't work on my system, I haven't found much. I'm looking for an example that illustrates how this works in general programming languages like Java, Python, C, or C++. It doesn't have to be game-related; a simple text-based chat app would be fine. Any resources or explanations on how it functions would be greatly appreciated! Networking feels really challenging to me, but if it was doable back then, I'm sure I can figure it out!
1 Answer
It seems like what's happening here is based on DNS Service Discovery (DNS-SD) combined with Multicast DNS (mDNS). These protocols are designed for easy service discovery across networks, meaning devices can find each other without prior configuration. Essentially, the tutorial you referenced develops a custom way to do this, where it broadcasts a message saying, "I'm a game server at 192.168.1.xxx, port yyyy." Game clients then hear that and can connect directly to the server. In contrast, mDNS works via clients sending out a request like, "Is anyone hosting a game server?" and the hosts responding back with their details. Once this discovery phase is complete, the specifics of your application come into play; you could set it up to let clients ask the server about player counts or active maps.

Yeah, I think I figured it out after some digging. Check out this project on GitHub that explores the topic: https://github.com/brainrot-coder-3000/minecraft-LAN