[INFSmartFoxiPhoneClientAPI_2X] Crash on decodeSFSObject

Post here your questions about the Objective-C API for SFS2X

Moderators: Lapo, Bax

Posts: 2
Joined: 15 Feb 2011, 07:33

[INFSmartFoxiPhoneClientAPI_2X] Crash on decodeSFSObject

Postby spotlessmind » 15 Feb 2011, 07:44


I'm realizing a service with SmartFoxServer 2X, my server is ok, my extension too and my Flash client to, but not my iPhone client !

All connections are okay, but not a return of my extension ! this extension works with my Flash Client, but not with my iPhone Client. I have got an error when my app has a result :
*** Terminating app due to uncaught exception 'SFSCodecException', reason: 'Invalid SFSDataType. Expected: 18, found: 120'
*** Call stack at first throw:
0 CoreFoundation 0x0155fbe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x016b45c2 objc_exception_throw + 47
2 LionCereales 0x0006d983 -[DefaultSFSDataSerializer decodeSFSObject:] + 202
3 LionCereales 0x0006f7fa -[DefaultSFSDataSerializer binary2object:] + 222
4 LionCereales 0x0005f1ba +[SFSObject newFromBinaryData:] + 72
5 LionCereales 0x000597ed -[SFSProtocolCodec onPacketRead:] + 50
6 LionCereales 0x00058051 -[SFSIOHandler handlePacketData:] + 781
7 LionCereales 0x00058dc5 -[SFSIOHandler onDataRead:] + 558
8 LionCereales 0x0004b44b -[BitSwarmClient stream:handleEvent:] + 1753
9 CoreFoundation 0x0153b1d2 _inputStreamCallbackFunc + 82

With this trace and the XCode debugger, i found where is a problem : in the function -(id <ISFSObject>)decodeSFSObject:(Data *)buffer.
In this function, the exception has thrown here :
id <ISFSObject> sfsObject = [SFSObject newInstance];

int8_t headerByte = [buffer readByte];

if (headerByte != SFSDataType_SFS_OBJECT) {
@throw [SFSCodecException exceptionWithReason:[NSString stringWithFormat:@"Invalid SFSDataType. Expected: %d, found: %d", SFSDataType_SFS_OBJECT, headerByte]];

Like my packet is not an SFSDataType_SFS_OBJECT !

But it's the same packet return in my Flash Client ! but why my iPhone Client crash, and not my Flash Client ???

Can you help me ?

Thank you

Posts: 2
Joined: 15 Feb 2011, 07:33

Postby spotlessmind » 15 Feb 2011, 07:51

I'm sorry for this topic, i haven't try the last librairy by Lapo... Now, i haven't crash !

Thank you Lapo !
Posts: 9
Joined: 06 Jun 2011, 07:10

Postby Areg » 13 Jun 2011, 12:07

I have got a similar problem in my iPhone app. Unfortunately, I am not sure which library do you refer by
the last library by Lapo...
I am using the client API library, which has been installed by default with the SFS2X version for Mac OS 10.5 +.
But the crash happens only when I dynamically create rooms with custom variables. These rooms are created every time a user joins the lobby room (which is created statically). Here is the server extension code which does the work.

Code: Select all

List<RoomVariable> vars = new ArrayList<RoomVariable>();
vars.add(new SFSRoomVariable("blind", 10, false, false, true));
vars.add(new SFSRoomVariable("speed", 15, false, false, true));
vars.add(new SFSRoomVariable("vip", false, false, false, true));
CreateRoomSettings crs = new CreateRoomSettings();
crs.setName("PokerRoom" + index++);

getApi().createRoom(getParentExtension().getParentZone(), crs, null);

Could anyone help me with my problem?
Posts: 9
Joined: 06 Jun 2011, 07:10

Postby Areg » 14 Jun 2011, 06:09

Just in case: the API version that I'm using is 0.8.6.
Posts: 9
Joined: 06 Jun 2011, 07:10

Postby Areg » 14 Jun 2011, 07:06

I did some experiments, and here is what I have found. The problem is not in te dynamically created rooms. Even if I create the statically (using the admin tool), then the crash happens if the number of rooms in a zone is >= 10. But I have set the "maximum rooms for zone" to be 500. Is it a limitation of the free version?
Posts: 9
Joined: 06 Jun 2011, 07:10

Postby Areg » 16 Jun 2011, 11:37

I've finally figured out the problem. If there were too many rooms/variables, then the packet size exceeded the protocol compression threshold. So, I was receiving compressed data on the iPhone side. Strangely, the client API could not figure it out and expected the incoming data to be plain text.
For now, I have increased the protocol compression threshold to continue my work. But I can not understand what should I do to enable handling of compressed data on the iPhone side? Are there some special configuration tags that should be put in the configuration XML file?
Posts: 21
Joined: 01 Nov 2011, 22:26

Same Issue

Postby ashutosh » 01 Nov 2011, 22:28

Hey I have the same issue, which library are you talking about? (The one you installed?)
User avatar
Site Admin
Posts: 4332
Joined: 29 Mar 2005, 09:50
Location: Italy

Postby Bax » 02 Nov 2011, 08:10

ashutosh, are you using the latest API version provided with the SFS2X RC3 patch? If not, please install the RC3.
Paolo Bax
The SmartFoxServer Team
Posts: 21
Joined: 01 Nov 2011, 22:26

@ bax

Postby ashutosh » 02 Nov 2011, 15:26

yes bax, RC3 patch is already installed.
Posts: 205
Joined: 09 Nov 2010, 00:48

Postby mmilen » 11 Nov 2011, 23:32

Same issue here with compression. I have a separate thread about it and the only solution is to basically disable the compression with a huge threshold (1GB).

My server is RC3
Latest iPhone API from Sept 9th 2011

First there is coding problem when packet is compressed to go to server. When I cleared the issue, the server throws error that can not decompress the packet. If you provide some details on the compression mechanism and what exactly the server expects I can help you with the code.
Posts: 21
Joined: 01 Nov 2011, 22:26


Postby ashutosh » 11 Nov 2011, 23:35

Bax is looking at the issue, I have sent him my crash log last week and he is looking into it.

Hope it's fixed soon..

Return to “SFS2X iPhone / iPad / OSX API”

Who is online

Users browsing this forum: No registered users and 2 guests