iOS SFS NSRangeException

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

Moderators: Lapo, Bax

eyalb
Posts: 9
Joined: 08 Jan 2018, 10:13

iOS SFS NSRangeException

Postby eyalb » 21 Mar 2018, 10:09

Hi,

I'm implementing some retry mechanism that reconnects to SFS after a disconnection (regardless of HRC).
Most of the times it works very well, but few times already I've encountered an exception (func -onSmartfoxException delegates) after the connect call:

exception.name: NSRangeException
exception.reason: *** -[NSConcreteMutableData getBytes:range:]: range {22, 77} exceeds data length 35
dataDump:
dataDump [size=358]:
Data Read: Binary Size: 80
80 00 4d 12 00 03 00 01 61 03 00 00 00 01 63 02 ..M.....a.....c.
00 00 01 70 12 00 03 00 02 74 6b 08 00 20 38 35 ...p.....tk...85
36 37 32 36 36 65 30 37 38 36 65 36 37 38 63 38 67266e0786e678c8
37 31 65 36 37 37 30 65 33 35 63 66 62 32 00 02 71e6770e35cfb2..
63 74 04 00 00 04 00 00 02 6d 73 04 00 00 27 10 ct.......ms...'.

Any help would be appreciated. Also - do you think a few seconds delay between the disconnection and the connect attempt might solve this?

Thanks,
Eyal Barak
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: iOS SFS NSRangeException

Postby Lapo » 21 Mar 2018, 10:47

Hi,
yes definitely, you should delay the reconnection by 500-1000ms minimum.
Also keep in mind that you need to recreate the main SmartFox object for a new connection.

Other than that you should be fine.
Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
eyalb
Posts: 9
Joined: 08 Jan 2018, 10:13

Re: iOS SFS NSRangeException

Postby eyalb » 21 Mar 2018, 14:45

I actually didn't realize i need to recreate the object..
Why is that?

Just to clarify, currently the order of actions is (on client side):
- init - allocating the sfs object
- connect with some ip and port
- login with some token (userName) , pass and zone
- few more inhouse stuff

After the disconnection (onConnectionLost) -
- now wait 500-1000ms
- connect with SAME IP AND PORT
- login with NEW token (userName)
- few more inhouse stuff

Thanks!
Eyal
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: iOS SFS NSRangeException

Postby Lapo » 21 Mar 2018, 16:31

Yes the flows looks correct.
Why do you have to recreate the object?
That's just how the API work across all supported platforms.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
eyalb
Posts: 9
Joined: 08 Jan 2018, 10:13

Re: iOS SFS NSRangeException

Postby eyalb » 22 Mar 2018, 11:34

So I'm confused because the flow doesn't include re-init of object, and you still said it looks ok.. so guess it's not?
And bottom line as a rule of thumb, any connect() should actually be made on a new object?

Thanks,
Eyal
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: iOS SFS NSRangeException

Postby Lapo » 22 Mar 2018, 15:58

Sorry I should have tried to explain this better.
I would simply add one step in the flow you posted earlier:

After the disconnection (onConnectionLost) -
- now wait 500-1000ms
- create new SmartFox2XClient instance
- connect with SAME IP AND PORT
- login with NEW token (userName)
- few more inhouse stuff


And bottom line as a rule of thumb, any connect() should actually be made on a new object?

Yes.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X iPhone / iPad / OSX API”

Who is online

Users browsing this forum: No registered users and 6 guests