Wrong XML Received

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

usacha
Posts: 3
Joined: 14 Dec 2009, 12:50

Wrong XML Received

Post by usacha »

Hello!
We're using SmartFox flash client, and some times (rarely) appears strange bug:

Code: Select all

TypeError: Error #1088: The markup in the document following the root element must be well-formed.
	at it.gotoandplay.smartfoxserver::SmartFoxClient/xmlReceived()
	at it.gotoandplay.smartfoxserver::SmartFoxClient/handleMessage()
	at it.gotoandplay.smartfoxserver::SmartFoxClient/handleSocketData()
	at flash.events::EventDispatcher/dispatchEventFunction()
	at flash.events::EventDispatcher/dispatchEvent()
	at it.gotoandplay.smartfoxserver.handlers::SysHandler/handleUserVarsUpdate()
	at Function/http://adobe.com/AS3/2006/builtin::apply()
	at it.gotoandplay.smartfoxserver.handlers::SysHandler/handleMessage()
	at it.gotoandplay.smartfoxserver::SmartFoxClient/xmlReceived()
	at it.gotoandplay.smartfoxserver::SmartFoxClient/handleMessage()
	at it.gotoandplay.smartfoxserver::SmartFoxClient/handleSocketData()
Server send us wrong XML like this:

Code: Select all

<msg t='sys'><body action='uVarsUpdate' r='73'><user id='140' /><vars><var n='moveType' t='s'><![CDATA[MOVE_CHOOSE_DICE]]></var><var n='params' t='s'><![CDATA[2]]></var></vars></body></msg><msg t='sys'><body action='uVarsUpdate' r='73'><user id='140' /><vars><var n='params' t='s'><![CDATA[1]]></var></vars></body></msg>
Could you tell how to avoid such situations?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Hi,
it is likely that there is a mismatch between your current server version and the client API.

Please tell me which Server version and API version you are using.
API version is obtained by calling the getVersion() method on the SmartFoxClient instance.
Lapo
--
gotoAndPlay()
...addicted to flash games
usacha
Posts: 3
Joined: 14 Dec 2009, 12:50

Post by usacha »

We have SF Server v1.6.6
and flash client V1.5.3

I've install flash client V1.6.1,
but this bug didn't fix there.
Problem is in function xmlReceived(msg:String):void
Sometimes server send us wrong xml that contains two messages
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

The problem with this issues is the ability to reproduce them. We have had a few reports about a similar problem but we were never been able to reproduce it. It might be related with specific network conditions...

Personally I remember having a problem that was similar when stress testing an early version of SmartFox with a firewall in between. The firewall was working good 90% of the times but under very high traffic it would start messing around with packets resulting in sporadic errors in SFS. After multiple headaches we realized it was the firewall, we removed it and never had the problem again, plus we were able to add more pressure to the stress tests.

If you can provide any more information we are interested in learning more and see if we can help
Lapo
--
gotoAndPlay()
...addicted to flash games
nizzle
Posts: 31
Joined: 20 Jul 2008, 11:41

Post by nizzle »

I get the same error 25% of the time, so it might have another cause. But here is the XML that is giving me trouble:

Code: Select all

<msg t='xt'>
	<body action='xtRes' r='-1'>
		<![CDATA[
			<dataObj>
				<var n='var_name1' t='n'>34</var>
				<var n='var_name2' t='n'>37</var>
				<var n='var_name3' t='n'>35</var>
				<var n='var_name4' t='s'>game_1_set_player_roles</var>
			</dataObj>]]>
	</body>
</msg>
<msg t='xt'>
	<body action='xtRes' r='-1'>
		<![CDATA[
			<dataObj>
				<var n='var_name5' t='n'>97</var>
				<var n='var_name6' t='b'>1</var>
				<var n='var_name7' t='n'>35</var>
				<var n='var_name8' t='n'>20</var>
				<obj o='var_name9' t='a'>
					<var n='3' t='n'>25</var>
					<var n='2' t='n'>35</var><var n='1' t='n'>34</var>
					<var n='0' t='n'>37</var>
				</obj>
				<var n='var_name10' t='n'>37</var>
				<var n='var_name11' t='n'>10</var>
				<var n='var_name12' t='b'>1</var>
				<var n='var_name13' t='n'>34</var>
				<var n='var_name14' t='n'>20</var>
				<var n='var_name15' t='s'>game_1_request</var>
			</dataObj>
		]]>
	</body>
</msg>
Same message is send to 4 or 5 other clients without a problem.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

This is really strange.
It is perfectly possible that 2 or more messages are aggregated in the same packet and the API handle this without problems.
Each message needs to be separated by the XMLSocket terminator byte (0x00) which marks the end of the message.
The API scan through the binary data and recreate messages by locating these end-of-message markers.

I have verified the code that does this in the API and it works correctly and I am not able to think of an exception where this might not work.
So one could hypothesize that the marker in between the two messages is not present, which is even more strange.

Since you are able to see these quite often, it would be great if you could capture one of these events and check the actual binary data.
If you want you can get in touch with me via email and I will provide some help to temporarily modify the Actionscript API in order to capture one these events.

hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
Sappho
Posts: 74
Joined: 29 Mar 2009, 19:23
Location: Slovakia

Post by Sappho »

I just want to add my 2 cents maybe it helps, this happens always when you don't handle your previous exceptions correctly. I am not saying that this may be your problem but to be sure always use debug player and check for unresolved exceptions inside your code. I am talking about all exceptions not only those inside your SFS code it can be inside your application something totally unrelated to SFS.

A lot of people let minor exceptions unresolved as a flash developer browsing Flash sites its quite often than i encounter various exceptions, mostly URLLoader ones. Why do people do this? ALWAYS handle all your possible exceptions, i know that the enduser without debug can't see them they DO break your application, this specific problem with SFS packets is one of them. If you run the debug is this the only exception you see? Its probably related to one that you got before it, i too had this problem quite a lot during game development but i never ever had this exception to pop up standalone.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Interesting post. However I am in trouble understanding this comment and I don't see how this could happen. Additionally the Flash Player is (thanks god) a single threaded environment so it's quite easy to follow the the code flow.

An error caused by your code will simply make the execution bubble up until a try/catch handler is found and eventually it will surface at the top as unhandled error if you run the debug player or it will be ignored by non-debug players.

This however will not hijack the normal execution of events fired by other objects such as the Mouse, Keyboard, Timers or the SmartFoxClient class.

In order to confirm this I have done a quick test with the AvatarChat example throwing an Error on each movement of the Avatar which results in an annoying popup in the standalone player. Besides that everything functions correctly even when running many clients all generating the error at runtime.
Lapo
--
gotoAndPlay()
...addicted to flash games
Sappho
Posts: 74
Joined: 29 Mar 2009, 19:23
Location: Slovakia

Post by Sappho »

Lapo thats interesting, for example i had simple unresolved exception by URLLoader and right after that these SFS XML exceptions started. Once i resolved the URLLoader exception the SFS had no problem. However now i too tried to make some forced test exceptions and SFS had no problem, strange, if i encounter some scenario which can be easily reproduced i will let you know.

You are right about the single threaded enviroment ofcourse, even thou there were times when i was wishing that i could created multi threaded application atleast inside AIR. For example when i decided to use AS3 for Google CodeJAM competition :)
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

However now i too tried to make some forced test exceptions and SFS had no problem, strange, if i encounter some scenario which can be easily reproduced i will let you know.
That would be great.
For example when i decided to use AS3 for Google CodeJAM competition
Cool :)
Btw, Timers can be a good replacement for threads and they don't introduce the intricacies of Java.
Lapo
--
gotoAndPlay()
...addicted to flash games
Sappho
Posts: 74
Joined: 29 Mar 2009, 19:23
Location: Slovakia

Post by Sappho »

Lapo wrote:Btw, Timers can be a good replacement for threads and they don't introduce the intricacies of Java.
I hope the offtopic isn't a bother. Anyway timers in AS3 still execute in the same thread which means they use the same CPU Core which was the problem since i run on Quad i wanted to utilize all 4 cores which isn't possible with Flash since it always runs only on 1 core :(
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Actually there is some support to multicores:
http://www.kaourantin.net/2007/06/multi ... pport.html
But probably it could be much better, although I don't think we'll see any improvements very soon.
Lapo
--
gotoAndPlay()
...addicted to flash games
nizzle
Posts: 31
Joined: 20 Jul 2008, 11:41

Post by nizzle »

Hate to get between two gals chatting and going all on-topic, but there is some truth to this. Whenever I get an error in the debug-versioin of the flashplayer, all (or most) server XML messages cause more error-popups complaining about the XML markup.

However, this is not the case in the example from my previous post.
Sappho
Posts: 74
Joined: 29 Mar 2009, 19:23
Location: Slovakia

Post by Sappho »

nizzle sorry for the offtopic, anyway good to know that i didn't have paranoia about the server XML messages going all crazy after some of the non-related Flash exceptions. Its also a hint for anyone else that has problems with this type of situation. Since i said i always had those errors only as a result of other non-related exceptions and SFS was all innocent in that scenario :)

Anyway any luck on reproducing the actual bug when it happens? I doubt the problem is in the XML you posted its probably somewhere in the client code.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Whenever I get an error in the debug-versioin of the flashplayer, all (or most) server XML messages cause more error-popups complaining about the XML markup.
If you can provide a simple example that reproduces the issue it would be great
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply