java - App Engine: Keep Socket Open more than 2 Minutes -


Using the App Engine Trusted Tester Socket to connect with APNS. Writing in the socket works fine.

But the problem is that the socket is retrieved after 2 minutes of inactivity. It has been said in the Trusted Tester website that a socket operation is responsible for the socket for 2 minutes. As long as the APNS decides to close the connection, it is good to keep the socket open.

After trying the socket API methods after typing in the output stream, the socket closes after 2 minutes.

you can not

keep the socket connected to the artificially open APNS ; The only way to keep it open without sending the actual push notifications is to send some arbitrary data / bytes, but the result will immediately stop the socket; The APNA closes the connection as soon as it detects something that does not conform to the protocol, that is, there is no real push notification.

SO_KEEPALIVE

What about SO_KEEPALIVE ? The app engine clearly states that it is supported. I think this means that when you call Socket.setKeepAlive (true) , it will not throw an exception; The call wanted to set the raised socket options, even if you enable to keep it on, if your socket is not sent for more than two hours, it will be recovered (closed) ; At least as of now on the App Engine

Actually, it is not a big surprise that the TCP specifies the living alive clearly that TCP keep is not sent more than once every two hours, and then, only then It is necessary if there is no other traffic, however, it also states that this interval will also be configurable, there is no API on java.net.Socket , you use it to configure Can (most) Nbavna because it can be set to 2 minutes on highly OS-dependent) and I doubt that App Engine.

SO_TIMEOUT

What about SO_TIMEOUT ? This is entirely something for javadoc of Socket.setSoTimeout ():

Enable / Disable SO_TIMEOUT with the specified timeout, in milliseconds. This option is set to non-zero time-limit, a read () call on the inputstream connected to this socket will be blocked for this amount only if the timeout is terminated, a java.net.SocketTimeoutException is picked up , Though the socket is still valid. To be effective, the option should be enabled before entering the blocking operation. Timeout should be & gt; 0. Time time out of zero is interpreted as an end time.

That is, when read () is being blocked for a very long time because you have nothing to read "Ok, ) Do not want to wait, and do something else instead ". This is not helping with our "2 minute" problem.

What then?

The only way to work around this problem is this: When a connection is retrieved / stopped, then throw it away and open a new connection.

Check-Out java-apns-gae .

This is an open source Java APIs library which was specially designed (and can be used) to work on Google App Engine.



Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -