Hey all.

I'm making an online game. It uses XML maps, and I was wondering...

what's the best way to transfer an XML file over a socket?

I want my server to send an XML map whenever it's requested, but I dunno how I'd get the xml from the other data sent by the server. (the map is probably 30kb and my client pulls in data at 1kb each time).

Any ideas?

> but I dunno how I'd get the xml from the other data sent by the server.
How many different types of data are there already?

Just add another (XML map fragment) to the data stream, and a length to tell you how big the fragment is.
0x00 0x0a .. .. .. .. .. .. .. .. .. ..
may be say a position update
0x01 0x10 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
may be say a map update

and so on

Thanks for your reply.

I guess I could do something like that ( #define F_POS 0x01 , #define F_UPDATE 0x02 etc.)

But how would the server parse that? Sorry, I'm new to this. Right now it sends strings, like "move:x:y" and stuff.

How would I make the server parse that, then parse the length, etc etc?

Well, I'm sending:

  • map:map.xml for when a player changes maps
  • move:x:y for when a player moves
  • chat:text for when a player says something
  • kick:player and ban:player
  • mode:player:mode a mod function

etc, etc.

So you send everything as text strings delimited by newlines then?
Which are then parsed at the other end to extract the info required.

Perhaps you could send a complex map as

map:map.xml
<mymap>
  <object></object>
</mymap>
map:endofmap

In other words, you just accumulate data until you see the end of map string.

Right, right; but what if the user requests a couple maps and they all get messed up? :p

Also, I don't really like using strings for socket data. Do you have an example of using hex or whatever in them?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.