Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

For my multiplayer game server, I made a class inheriting from "Microsoft.Xna.Framework.Game", just like I did for the client-side part.

The thing is, I don't need any graphical display for the server, so I end up with a useless blank game window floating around. Also, the LoadContent/UnloadContent and Draw overrides are left empty. On the other hand, I still need to use Microsoft.Xna.Framework.Game for the game loop and logic update parts.

So is there any special class in XNA made especially for the server-side part, or is everyone else doing it just like I do?

share|improve this question

4 Answers 4

up vote 3 down vote accepted

There is no class that is part of the XNA library that acts as a game server.

You probably should not use the framework to write the server code unless you are creating a peer to peer Xbox based game over Xbox Live. I assume that you are not doing so because you would then need to render things onto the screen.

All C# programs start in the public static void Main method, including a program begun with the XNA framework.

If you do not already know how to create a program and import the XNA libraries without using the framework, you may be in over your head when it comes to the creation of a multiplayer game.

share|improve this answer

An XNA application is a .NET application, just like any other. In your Program.cs on the server, don't call the constructor or Run() for the Game class; just run your server logic instead.

share|improve this answer
    
But if I do that, I won't have the game loop that the Game class provides. So I won't be able to update the game state at a fixed interval of time. –  asmo Jun 5 '11 at 21:59
1  
You could use the System.Thread.Sleep(time) to update something at a fixed interval of time, and create your own server-side game loop manually –  IDWMaster Jun 5 '11 at 22:02
2  
On a server why would you want a 60-times-per-second loop anyway? Wouldn't you rather have the control to make the server run faster or slower? –  Jonathan Hobbs Jun 6 '11 at 1:44

Why is it a problem that your game doesn't draw anything?

It seems like you're tilting at windmills.

If you want you can make a console application and then just import the XNA networking classes that you actually need, or make any other type of application, and import the XNA networking stuff. If you need a fixed time update loop, that is pretty trivial to implement.

You can create a windows forms application, and use it with XNA, by following the information here: http://forums.create.msdn.com/forums/t/6471.aspx

You probably want your server to draw something though, like the current status, or provide some sort of GUI controls.

share|improve this answer

What kind of multiplayer server you are going to write? Is this just a lobby server for setting up peer-to-peer games? Is this a full on multiplayer server that is dedicated to hosting the game and communicating with clients (like Counterstrike servers, for example)? Or are you wanting to add multiplayer capability to your game in which a player starts a game that others can join?

If the last variant is what you want, XNA/.NET do provide some networking classes.

If you want to create a dedicated multiplayer server, you should do as HydroxicAcid says and avoid using the entire XNA framework as you will not need much of what it provides. What you should do is isolate your logic from your rendering code (in separate assemblies!) so that you can reuse these classes in your server application. You'll want to look into serialization over a network of figure out some lightweight message format for transporting gameplay data. There may be some instances where a 1:1 match between how a game object is represented on the server must be very different from how that same object is represented on the client, so be prepared to deal with that.

If you want to create a lobby server, you probably don't need to even write it in C# or use the .NET framework or even run it on a Microsoft platform. Its sole purpose is to find other people that want to play the game and tell them about each other, so there will likely be no need to reuse any existing game code for that.

Whatever it is you're looking to do, you can find a lot of good resources on AppHub => http://create.msdn.com/en-us/education/catalog/?devarea=19

share|improve this answer
    
That's brilliant. The separating logic idea. –  AgentFire Mar 24 '12 at 6:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.