Connecting across a LAN
If you're interested in writing games that can operate across a LAN, then there's a very good chance that you'll be interested in some sort of broadcast messaging service to initially allow clients to discover each other, and possibly for fast peer-to-peer game play.
This example demonstrates how to send and receive broadcast messages between both clients on local, as well as remote, machines.
Getting ready
This example requires a SpriteFont
file with the asset name of Text to be present in your solution. As it's purely for debugging purposes, any typeface and size will do.
How to do it...
To start broadcasting across the network yourself:
1. Add a class named
BroadcastClient
to the solution:class BroadcastClient {
2. Insert the instance-level variables to hold the state of the broadcast networking client:
const int udpRangeStart = 15123; const int localMaximumPortCount = 16; UdpClient udpClient; IPEndPoint udpReceiveEndPoint; List<IPEndPoint> udpSendEndPoints;...