UDP timeout

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

Moderators: Lapo, Bax

User avatar
janheuninck
Posts: 68
Joined: 23 Nov 2011, 01:35
Location: Vancouver BC, Canada

UDP timeout

Postby janheuninck » 24 Aug 2013, 21:47

We are experiencing a problem with the iOS client lately. Whenever the client logs in into a zone, we initialize the UDP protocol. When this succeeds we let the user join the game room. So far so good.

But when a user doesn't send a UDP packet to the server for a consecutive 30 seconds and after that tries to send a packet over UDP, the server won't process the message:
Discard UDP packet from ..., reason: Sender UDP Port doesn't match current session port: 63836 != 30820


I've looked into the iOS API for a property to know if the UDP socket is no longer valid, but that doesn't seem to be available. Otherwise we could re-initialize the UDP protocol.

Edit: The TCP socket keeps working fine.

Thoughts?

We are using the iOS API v1.1.5 and server version 2.6.0


Cheers
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: UDP timeout

Postby Lapo » 25 Aug 2013, 15:22

Interesting, thanks for posting.
UDP on mobile devices can be a strange beast, partly because of how it's implemented but also because of all sorts of limitations from carriers.
I am also partially impressed by the fact you can use UDP at all, unless maybe you're talking about UDP over a wifi connection?

Is it wifi? or 3G?

UDP is connection-less although most user level API will mimic a TCP-like approach where some sort of connection is established. Typically this means that when an application requires UDP communication the OS will reserve one local free UDP port for the client. The reserved port is not expected to be reassigned or revoked at any time unless the owning application quits, thus freeing it up.

What it seems to be happening is that the assigned port is revoked after an extremely short amount of time, those 30 secs.
But again, testing under wifi vs. 3G might make the difference

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
janheuninck
Posts: 68
Joined: 23 Nov 2011, 01:35
Location: Vancouver BC, Canada

Re: UDP timeout

Postby janheuninck » 25 Aug 2013, 15:28

Yes, we only use the WiFi connection of the devices (iPads). The revoking of the port after the application moved to the background seems like a reasonable explanation.

I was hoping I could detect this and then re-initialize UDP once the application comes to the foreground again. This is not possible with the current API. Any idea if this would be possible to implement? Our current workaround is to completely disconnect from the game server when the application is moved to the background and start all over again (setup SmartFox Client instance, login and init UDP) when it becomes active again.


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

Re: UDP timeout

Postby Lapo » 25 Aug 2013, 15:36

janheuninck wrote:Yes, we only use the WiFi connection of the devices (iPads). The revoking of the port after the application moved to the background seems like a reasonable explanation.

I see, but is it what is really happening? You didn't mention the app going to background in the first post. A

I was hoping I could detect this and then re-initialize UDP once the application comes to the foreground again. This is not possible with the current API. Any idea if this would be possible to implement?

No it is indeed not possible, I think. We'll have to test more in depth.

Our current workaround is to completely disconnect from the game server when the application is moved to the background and start all over again (setup SmartFox Client instance, login and init UDP) when it becomes active again.

Just to fully understand: the UDP port seems to be revoked ~30sec after the application is put in the background?
Is this a consistent behavior?

Have you tried putting the app in the background for a shorter amount of time and see if UDP is still available?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: UDP timeout

Postby Lapo » 25 Aug 2013, 15:37

One more thing. If the server pings the client with an emptu UDP packet every 10 seconds wouldn't it fix you issue? (at least temporarily)
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
janheuninck
Posts: 68
Joined: 23 Nov 2011, 01:35
Location: Vancouver BC, Canada

Re: UDP timeout

Postby janheuninck » 25 Aug 2013, 15:47

Yes, that's what we are doing right now (in case the player doesn't move for a while). The problem is that all network traffic is discarded when the application runs in the background (so the ping messages won't be send).

Return to “SFS2X iPhone / iPad / OSX API”

Who is online

Users browsing this forum: No registered users and 22 guests