johnnycash
12-18-2008, 12:08 AM
Hi. I have to use XMLSocket in a multiplayer realtime game. I have to decide if I'm gonna use XML for the protocol encoding or not. The advantage of using XML it is that is easier to parse I guess, but it adds an important overhead to each message. Can a few extra bytes make the sending of a message slower? Any ideas?
Thanks in advance.
NickZA
12-18-2008, 09:36 PM
johnnycash,
This depends a lot on how many messages you'll be sending. If it's only a turn-based game, I would wholly endorse using straight XML. If you're talking real-time, but a simple client-client or client-server connection (2 machines total) with a low number of updates per second, I wouldn't worry -- today's systems are quite fast enough to handle a bit of XML decoding, even in Flash.
But if it's a real-time game, perhaps with many updates per second and with more than two players, I guess you'd be wise to begin considering your options, meaning sending raw or minimally formatted data. Think about it in terms of bytes sent, as bandwidth is essentially the bottleneck: you're doubling your bandwidth requirement. If you have 4 players instead of just 2 in your game, it can be double (or more, depending on how messaging is routed or not routed) again. Because many packets are sent every second in a multiplayer game, you will want to think very carefully about letting this get out of hand -- and doing calculations is a good idea.
It's really a trade off. Deserialising formats like XML and JSON (http://en.wikipedia.org/wiki/JSON) require more work on the client side, but generallyspeaking it's better to do more work on the client or server than to feed more data through your network connection.
JSON is an interesting option if you have low requirements, due to it's being a somewhat more natural form of representing objects and simple data structures, however I don't believe it is parsed that quickly by the AVM (may be wrong here).
Something to be aware of if you want smooth-looking movement and response without many updates per second is dead reckoning, see here (http://www.gamedev.net/reference/programming/features/cubicsplines/default.asp).
A good article (and site, in general) for getting to grips with some general networking optimisation concepts is here (http://www.gamasutra.com/view/feature/3094/1500_archers_on_a_288_network_.php?page=1).
EDIT: There are some excellent articles on various game development sites that deal with this sort of thing, actually showing you how you would do calculations to figure out how many bytes you'll be sending/receiving. Unfortunately I can't think of them off the top of my head. Here is one (http://blogs.adobe.com/mikepotter/2006/07/php_and_flex_js.html), but please don't take that as the final word -- it depends on how your code works (also bear in mind that link deals with populating data in a Flex datagrid)!
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.