TCPClient for a Host Game/Join Game setup
Scenario: Basically I want the user to be able to click host game and it put him in a lobby waiting for others or the user clicks join game and it shows a list of games on th开发者_如何学运维e screen. The game is being made in C# .Net 3.5.
Problem: I need help with getting a list of servers on the network. This would all be done over LAN. We have the server/client talking to each other so all I should need is the list of servers and just switch between them.
Any help is appreciated. TIA.
There are many ways to do this and as such, there is no single best approach.
At the top of my head, you can have your servers send UDP broadcasts that describe what games they are currently running, the host, and other info.
You can then have clients listen for such broadcasts on an assigned port, to build and refresh their list of servers/games.
Whether it is over a LAN or over the internet, what you're talking about is a master server. It's sole job is to provide a directory over what games are running.
- Create a Master Server program that acts as a directory to games.
- Each time somebody hosts a game, it connects to the Master Server giving the IP address and any other pertinent information.
- Clients connect to the master Server which returns a list of any games that it knows about.
This is pretty easy stuff, and you can add extra information as you see fit such as game information. All the master-server does is act as a directory to the rest of the games on the LAN.
精彩评论