Game Development Community

XNA 2.0 network

by Chris Kim · in Torque X 2D · 09/05/2007 (11:18 am) · 11 replies

I was listening to XNA 2.0 network presentation and I have few questions.
The background of the questions comes from builing a casual online game that will have separate lobby server. Lobby server will not be based on XNA.
And the lobby server will replace XNA lobby functionality but I like to use XNA session management functionality once gamer start/join a session.

1. Does XNA network requires to work over Live network? or can it work with Live?
It mentioned system link and match making requires Xbox membership and I thought it was designed to work with Live only. I hope it's optional and not a requirement.

2. XNA network is based on reliable UDP and it will be encryped, thus it cannot talk to my lobby server.
And there is no mention about TCP. I tried to send binary packet over network using System.Net but it's not that stright forward in C# doing packing and unpacking.
Will GG provide TCP packet reader and writter similar to MS UDP reader and writter?
I like basically to use MS reliable UDP for sessions and game play, and use TCP to communicate the server.

3. XNA 2.0 network is pretty much low level without object syncronization support. Will GG add it on top of it?

4. XNA 2.0 will be released at the end of this year. What would be the timeframe of TorqueX with network support?

Thanks a bunch.

#1
09/05/2007 (2:24 pm)
Right now, I don't think anyone knows. Or at least those who do know are under NDA's to not discuss the changing state of the network functionality that is coming at the end of the year lest it lead to a whole host of incorrect information.

But I do not think, though also do not know, that GG will add anything on top of the XNA layer lest it completely and totally break network functionality for future versions of XNA and TorqueX. Unless they are PC only, but then why not use one of the numerous .net network libraries out there?

I believe the answer to the last question was ASAP, but it will have to be compliant with the final version of XNA 2.0, which could lead into the coming year a bit.
#2
09/05/2007 (2:43 pm)
1. The networking support is based on Live sessions. You can't connect to arbitrary servers.

2. We probably won't initially add any extra support to circumvent the Live system, though you can use the .Net stuff to get it working on Windows.

3. XNA networking has no direct synchronization support. We haven't decided yet whether or not we'll be adding extra synchronization features to Torque X. If we do, it will probably be something very simple, such as a networked object component that allows you to synchronize interfaces between clients within a session.

4. The networking functionality in XNA is packed into a separate XNA game component, so there's nothing in Torque X that would keep you from using it in any Torque X game. There are, however, quite a few fairly significant changes to the Torque X framework that could potentially hinder backwards compatibility with games built on Torque X 1.0. Nothing too painful, but it's important to understand that there will be a little work involved in updating existing games if you plan to upgrade to the newer version of the engine. We may have a scene converter, but your code will most likely need to be updated as well.
#3
09/05/2007 (9:18 pm)
I'm really disappointed to hear that network must require Live.
It's pretty useless for me as I plan to have a separate server.
I'll just stop waiting and continue using System.Net.

I find that sending structures through byte stream, packing/unpacking is not straight forward in C#.
Why is that?
I don't know how MS do that but if I find the way, I can forget about XNA 2.0 network.
Packing/unpacking topic probably needs a separate thread. (but quick pointer to helpful link is appreciated)
Thanks.
#4
09/05/2007 (9:24 pm)
I've never personally worked with it. I'd probably just google it, though another thread might be useful. I'm sure there are others who could benefit from any information you find.
#5
09/06/2007 (12:58 pm)
I'm really disappointed to hear that network must require Live.
It's pretty useless for me as I plan to have a separate server.
I'll just stop waiting and continue using System.Net.

I find that sending structures through byte stream, packing/unpacking is not straight forward in C#.
Why is that?
I don't know how MS do that but if I find the way, I can forget about XNA 2.0 network.
Packing/unpacking topic probably needs a separate thread. (but quick pointer to helpful link is appreciated)
Thanks.
#6
09/06/2007 (3:20 pm)
Time paradox?
#7
09/06/2007 (10:26 pm)
Not sure what happend. ;)
#8
09/07/2007 (4:27 pm)
Creepy... haunted forums!
#9
09/09/2007 (1:48 am)
@Chris
If you want it totally managed, and don't want to interfere with the GC too much, you would normally use a BinaryReader to fill your struct - probably in the constructor. It looks something like this:

System.IO.BinaryReader br = new System.IO.BinaryReader(dataStream);
myStruct.Property1 = br.ReadInt32();
myStruct.Property2 = br.ReadByte();
etc, etc

Serializing is similar, except you use a BinaryWriter.

If you don't mind monkeying around with the GC, you can use some unsafe code to do it. It looks something like this:

using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential)] // make sure the CLR doesn't rearrange memory for us
struct MyStruct
{
int Property1;
int Property2;
}

...
MyStruct myStruct;
unsafe
{
fixed ( byte *byteData = streamData)
{
myStruct = *(MyStruct*)byteData;
}
}


Since you're fixing memory, the GC won't be able to optimize it which will affect performance. Also, unsafe code kind of defeats the purpose of using .NET to begin with.

Finally, you should also be able to de/serialize using the [Serilizable] functionality with a BinaryFormatter. The auto-magic serialization in .net uses reflection, however, which costs more performance than it's worth in my experience.

I would advise you to go with the BinaryReader/Writer option. It's fast, safe and straight forward, but takes a little more typing.
#10
09/10/2007 (10:52 am)
Thanks Kai,
It will be very useful for me to test.
Just to be complete, what would be the equivalent for packing?

will this work?
unsafe
{
(MyStruct*)byteData = &myStruct;
}

Thanks.
#11
09/10/2007 (11:23 am)
Change it to

byteData = (byteData*)&myStruct

You might want to keep track of the network game license question raised in
www.garagegames.com/mg/forums/result.thread.php?qt=66839
and for the latest answer check
www.garagegames.com/mg/forums/result.thread.php?qt=64536