View XML output?

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

Fishypants
Posts: 57
Joined: 26 Oct 2010, 14:03
Location: South Pasadena California
Contact:

View XML output?

Postby Fishypants » 02 Feb 2011, 20:34

Hey everyone, I am using SmartFox with Unity. I was wondering if there was an easy way to see what your data looks like as XML before it is sent as an object to the server?

Like, the full XML code. I have a few ideas on how to optimize it, but I'm not sure exactly if it is working without seeing what is being sent. Thanks!
Fishypants
Posts: 57
Joined: 26 Oct 2010, 14:03
Location: South Pasadena California
Contact:

Postby Fishypants » 03 Feb 2011, 16:28

Anyone?
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 03 Feb 2011, 16:56

Unity uses a different client API. So you may find your answer under Unity section the forum.
Smartfox's forum is my daily newspaper.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 04 Feb 2011, 07:24

Should be in the logfiles really if you look at what the client sends to the server. It prints out the string - and you can copy that over and have your xml editor format it for you into readable content.

You simlpy need to register for debug messages, and yoiu should get the callback

From API code:

Code: Select all

         DebugMessage("[Sending]: " + xmlMsg + "\n");
Fishypants
Posts: 57
Joined: 26 Oct 2010, 14:03
Location: South Pasadena California
Contact:

Postby Fishypants » 04 Feb 2011, 15:24

Thanks again Thomas!
*Sigh* - Stupid rookie mistake. Of course I had the debug message method setup in the login scene, but forgot to include it in the main game. . . Anyways all is good now. :D

I am glad that I can finally see what I am sending as full XML. I have been working on how to optimize what I am sending, and instead of creating an object with multiple variables, I condense everything into a single string and send that. Looks like it shaves a bit off the amount of data that is being sent:

<msg t='sys'>
<body action='asObj' r='3'>
<![CDATA[<dataObj>
<var n='_cmd' t='s'>*:0:0:1:0:False:0:-0.09254482:0.04:moving</var>
</dataObj>]]>
</body>
</msg>


This part is the beef of the data:
*:0:0:1:0:False:0:-0.09254482:0.04:moving


Basically I just tokenize the string using ":", and get the values. I am going to optimize it even more. First part is player movement vector, which since WSAD movement results in 8 axis values (9 if you consider Vector3.zero), I can just use an integer ranged between 0-8. Instead of true false for strafing, I can use 1:0, and for what state I am in, I can just use integers instead of "moving" "running", etc. I was even thinking about adjusting the game, so the floating point precision of the position vector gets rounded up to say the nearest two decimal places, just to avoid numbers like 1.234534324523452.

I will have to read up on SFSObject. Ideally I think I could shave even more data off by instead of using a dictionary system, if it allows to just send a single string. Will look into that. Thanks again!
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 05 Feb 2011, 08:27

Hye - you can also send your extension messages as strings - "no"/minimal xml fluff around it. alternatively as json. All smaller than xml in the first place.

And dictionary systems for sending strings make things even smaller - very good idea to use that. I remember Torque game engine having something similar semi-automagic

/Thomas
Fishypants
Posts: 57
Joined: 26 Oct 2010, 14:03
Location: South Pasadena California
Contact:

Postby Fishypants » 05 Feb 2011, 17:47

Good to know, I have actually been meaning to look at json, I heard that it is much more compressed. I will have to read up on how to use it. Does it send it as binary or does it just not have xml fluff around it?
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 06 Feb 2011, 07:44

Its still all text - if you want binary protocol you should go SFS2X

The string method is the one you really want if using SFS1 - doing what you already do with making your own meta protocol. json still has overhead in bandwidth. Just not as much as xml

/T
Fishypants
Posts: 57
Joined: 26 Oct 2010, 14:03
Location: South Pasadena California
Contact:

Postby Fishypants » 06 Feb 2011, 09:02

Hey Thomas, I was trying to read through the docs, but am unsure as to where I should look for sending a string as opposed to an object. Would this just be sending a public message / private message? Or is there something more specific on how to do this?
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 06 Feb 2011, 09:42

There is a parameter you can give the sendXtMessage that specifies if you want to use XML (default), json or string based protocol for this exact XtMessage.

E.g.

smartFox.sendXtMessage("gameExt", "fire", params, SmartFoxClient.XTMSG_TYPE_JSON)

/Thomas
Fishypants
Posts: 57
Joined: 26 Oct 2010, 14:03
Location: South Pasadena California
Contact:

Postby Fishypants » 06 Feb 2011, 15:35

Ahhhhhh, got it. Awesome, thanks Thomas! :D

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 24 guests