Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
ayyrk #1
Member since Jul 2007 · 92 posts
Group memberships: Members, Premium
Show profile · Link to this post
Subject: keep alive
Alex,

Do you have any experiences with the Keep-Alive setting in SmartJab to share?

I am using a keep-alive of 60 seconds in a WM5 application.

I am beginning to experiment with this parameter to try and make the socket connection more stable.

Any extra info you have would be greatly appreciated.

Thanks and Kind Regards,
Avatar
Alex #2
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
We run all our tests on Wireless LAN. We have not much experience with GSM or UMTS or switching between this connection.
The keep alive is meant for Modems and NAT's which disconnect idle connections.

If you have a unreliable connection HTTP-Polling and HTTP-Binding may work better than a persistent TCP/IP connection.

Alex
Avatar
ayyrk #3
Member since Jul 2007 · 92 posts
Group memberships: Members, Premium
Show profile · Link to this post
I haven't tested with HTTP polling yet. The Socket connection seems to work pretty well.

My concern with HTTP polling (and I may be very wrong here) is that it will generate more network traffic. I am trying to keep network traffic to a minimum.

I will dig into the periodic disconnect problem and get more information. I am just starting to look at this now.

If anybody out there has tuning tips for agsxmpp over GPRS please share!

Thanks!
Avatar
Alex #4
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Yes Polling creates much more traffic.
When your GPRS works pretty well then there is no reason to switch to another transport layer.
Make sure that your server supports stream compression and its enables if you want to keep the traffic.
You can really safe lots of traffic with stream compression on long lives sessions.

Alex
Avatar
Koterpillar #5
Member since May 2007 · 32 posts · Location: Russia
Group memberships: Members
Show profile · Link to this post
I run agsXMPP over GPRS a lot (WM5, WM6), with some modifications.
First being replacing Send(" ") with sending a Ping (there's a XEP) for keep-alive. I'm actually afraid compression will sometimes eat the space.
Second, very helpful one, is reconnection. I've found out that InitSocket(); before Open(); will lead to much earlier reconnection, as the old socket becomes way unresponsible after GPRS drop or such.
nebohodimo IM developer
Avatar
ayyrk #6
Member since Jul 2007 · 92 posts
Group memberships: Members, Premium
Show profile · Link to this post
Hi - It is good to hear you run agsXMPP over GPRS a lot.

Here's what I am seeing:

When the device is on battery the onClose event fires every 5 minutes. That triggers the application to reconnect and in less than 5 seconds it is back on line. (Device: HTC WM5 GPRS)

This doesn’t happen when the device is plugged in to a charger; the device stays online while charging.

Desktop chat clients like Spark see the WM5 contact briefly switch from available to unavailable then back to available. That is especially annoying when Spark is configured to popup a notice whenever a contact becomes available.

I don’t understand why onClose is fired every 5 minutes on battery. The device can reconnect right away but all this coming and going is annoying and seems wasteful of network bandwidth.

Have you ever seen anything like this and how does your app work while on battery power?

Thanks
Avatar
ayyrk #7
Member since Jul 2007 · 92 posts
Group memberships: Members, Premium
Show profile · Link to this post
To be more clear:

The WM5 device power applet (start/settings/system/power) is configured like this:

On battery Power:
[X] Turn off Device if not used for [3 minutes]

On external Power:
[ ] Turn off device if not used for [     ]
 
It looks like the device is turning off and an onClose event is fired. But the application logic that immediately reconnects the device causes it to not complete the "turn off".  The result is it disconnects and reconnects every 5 minutes. (why not 3 minutes who knows)

Now that I'm getting a better idea of what's going on I can start thinking about the best way to handle it.  I think the "turn off device" setting causes a periodic onClose event. It confused me that the "turn off" never completes though. I think my reconnect code is somehow canceling the "turn off". The result is the periodic disconnect/connect.

What I expected to happen when the device turned off was the user becoming "unavailable" in other peoples roster. Then when the power button was pressed the device would reconnect and the user would become "available" in other peoples roster.
Avatar
Koterpillar #8
Member since May 2007 · 32 posts · Location: Russia
Group memberships: Members
Show profile · Link to this post
In reply to post #6
Ah, yes, one more trick. Call this each minute or how do you see fit.
  1.         [DllImport("coredll")]
  2.         extern static void SystemIdleTimerReset();
This prevents standby mode. Please don't confuse the terms; standby and not power-off it is.
nebohodimo IM developer
This post was edited on 2007-12-13, 15:12 by Koterpillar.
Avatar
Alex #9
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
agsXMPP raises the OnClose when:

  • there is an XML error in the stream and it gets closed for that reason.
  • the server closed the stream/socket
  • the client closed the stream
  • There was an socket error or socket disconnect which interrupts the xmpp conenction.

I assume you get socket socket disconnects for some reason. You can debug agsXMPP and set breakpoints in ClientSocket.cs.
If you get disconnects this can also be related to your device or provider.

Alex
Avatar
ayyrk #10
Member since Jul 2007 · 92 posts
Group memberships: Members, Premium
Show profile · Link to this post
Here is what I learned about how the AGSXMPP SDK and the Windows Mobile 5 “start/settings/system/power/advanced” settings interact.

If the device is configured to turn off if not used for xx minutes then the onClose method is raised when the device tries to turn off. I expect it is the result of the stream closing on the device.

If a new connection is attempted when the onClose event is raised then the device reconnects to the server for about another xx minutes. It never fully turns off. The server sees it as briefly unavailable.

If the device is not configured to turn off when idle then it stays connected to the server.

I have tried this on devices with and without active sync direct push email. Direct Push email is supposedly keeping a long lived https connection open to the exchange server. I don’t know if the https connection is also broken and re-established when the device tries to turn off. I just don’t have visibility to that.

I thought maybe the direct push configuration would keep sockets open (by putting the device in the unattended power state) but it doesn’t; I have not seen any difference in the behavior of agsxmpp with/without direct push email.

I don’t like that the connection is broken and re-established when the device tries to turn off. It generates a lot of coming and going in other peoples rosters as the devices go unavailable and immediately reconnect.

I may add logic to the application that tracks user activity between onClose events. If there is no user activity between a few consecutive onClose events then I will wait for user activity before re-opening agsxmpp. That way a device can idle down to an unavailable state and stay there until the user picks up the device and presses a key.
Avatar
Alex #11
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
ayyrk,

  • agsXMPP is using only the .NET sockets.
  • The XmppClientConnection with XmppConnectionState == Direct is a long living TCP/IP connection
  • HTTP and HTTPS are no long lived connections.
  • When your device switches to idle mode it will shutdown all active sockets, which of course kills the XmppConnection and raises the OnClose.

I don't know how Windows Mobile detects system idle, but according to your posts existing active sockets are ignored.
Maybe periodic HTTP requests which open a new socket prevent the system from switching to idle mode.

Did you try Koterpillar suggestion of calling SystemIdleTimerReset? I have not tested this code but it sounds very good to me.

Active GPRS and WLAN connections consume lots of battery power, which is the reason why they normally don't stay active in idle mode. Depending on the device you will run out of battery power very fast if you keep the connection alive.

Alex
Avatar
ayyrk #12
Member since Jul 2007 · 92 posts
Group memberships: Members, Premium
Show profile · Link to this post
Alex - I agree with everything in your post.

Here’s what Microsoft says about Direct Push: “Mobile devices that support Direct Push issue a long-lived HTTPS request to the Exchange server. The Exchange server monitors activity on the users’ mailbox and sends a response to the device if there are any changes, such as new or changed e-mail messages or calendar or contact items. If changes occur within the lifespan of the HTTPS request, the Exchange server issues a response to the device that states that changes have occurred and the device should initiate synchronization with the Exchange server. The device then issues a synchronization request to the server. When synchronization is complete, a new long-lived HTTPS request is generated to start the process over again. This guarantees that e-mail, calendar, contact, and task items are delivered quickly to the mobile device and the device is always synchronized with the Exchange server.”

I can say that Direct Push enabled devices seem to immediately receive new emails.

I am just confused by the power saving states on WM5. This is not an AGSXMPP issue.

If I leave the device idle the screen goes blank and all of the hardware buttons except for the power button are disabled. The device can be turned back on by pressing the power button. The device will also enter this state from the ON state when the power button is pressed.

While the device is in this state (maybe what the Microsoft documentation calls the Unattended state) it is still running my client application and about every five minutes the onClose event is raised. The onClose event is not raised if there is user activity or if the device is not configured to turn off after an idle period.

I don’t think there is anything I can do about this. I have to configure the device to turn off after about five minutes or the battery will drain. With this configuration an onClose is raised when the device tries to turn off. The unexpected thing is that a reconnect issued after an onClose does succeed.

Here what I think I’ll do: If I detect the device is in this open/idle/onClose loop then I will break out and force the user to manually reconnect. That is better than having the device sit there wasting battery power.

I'm just working out how to best use your API on power saving devices - I bet Direct Push has to re-issue the HTTPS request every 5 minutes, I can't see how else it could do it..
Avatar
Alex #13
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Do you have more info about the so called "long-lived HTTPS connections"?
Normally a HTTP(S) connections time out when there is no response.

If its really a long lived (persistent) connection then it would waste also battery power.
Is it possible that the device polls the exchange server every x minutes?

Did you try XEP-0025: Jabber HTTP Polling
With the correct server and client configuration this works very well.

Alex
Avatar
ayyrk #14
Member since Jul 2007 · 92 posts
Group memberships: Members, Premium
Show profile · Link to this post
Here is more information regarding long lived HTTP requests

http://msdn2.microsoft.com/en-us/library/aa446486.aspx



My Status:

I use the agsxmpp SDK for two things. 1) A chat screen 2) updating device cached data. The "chat" feature is standard Instant Messaging. The "updating device cached data" pushes an xml file to the device.

Right now the onClose event is being raised and I immediatly reconnect. The result is that the device never fully turns off. The device cache stays up to date but the user toggles between unavailable and available and battery power is not conserved.

The onClose event is tied to the device setting for "turn the device off if it is not used for xx minutes". With this set the device tries to turn off and the onClose event is raised. If this is not set then the device simply stays connected.

So I want to keep the device cache up to date but must also conserve battery power. I am now considering this: Let the device fully turn off by not automatically reconnecting after onClose is raised. Then wake up the device every 20 minutes, connect, update the device cache, and put the device to sleep. As described here:

http://blogs.msdn.com/windowsmobile/archive/2004/11/29/271…
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP RSS